3 ms·
There's potential for optimization if the code executing the query can "understand" what it means. E.g. an SQL engine can potentially use an index to answer x<
by detaro 8y ago
There's potential for optimization if the code executing the query can "understand" what it means.
E.g. an SQL engine can potentially use an index to answer x<3. Your library calling your function for every item probably can't do that, or can't guarantee that it can do that.
- amelius 8y agoThere's still potential for optimization, it's just a little harder, because you'd have to parse and process the JS. But ... you don't have to invent a new language.
- detaro 8y agoI'd argue the difference between the two isn't just "a little harder", and is not the same as your function call example: in most languages, you can't or can't always access the source of a function you've been passed, so the code would need to be passed as text. If you define a subset of JS you accept, you've created a DSL. This can be a completely valid way of creating one, and if you actually want to fully interpret it picking something where you can bind a high-quality existing interpreter makes sense, but custom ones have their strengths too, especially if you otherwise would cross paradigms (e.g. the examples in the article seem clearly more like a declarative language).