3 ms·
This is tricky and there are certainly limitations. For example, you can't translate an if statement, so instead we implement our own branch command (http://ret
by coffeemug 13y ago
This is tricky and there are certainly limitations. For example, you can't translate an if statement, so instead we implement our own branch command (http://rethinkdb.com/api/#rb:control_structures-branch http://rethinkdb.com/api/#rb:control_structures-branch)
We overload operators when we can (unfortunately no operator overloading for Javascript folks) and it works really well.
You don't always get a great exception, but most of the time this turns out to be fine. Novices don't need to worry about this too much, and we found that as people get more into ReQL, they pick everything up extremely quickly, and they rarely confuse things or make mistakes.
- hosay123 13y agoThere are two alternatives to what RethinkDB does: parsing the function's associated source file (yucky and breaky when multiple lambdas per line) or disassembling its func_code.. I've looked at this problem before (and ran away screaming every time), but the approach I tended towards was func_code disassembly, pretty much for the reasons you mention. Was this ever considered?
- coffeemug 13y agoWe did look into disassembly, but decided that it's far too much work because it is not portable across languages and drivers, and would require an enormous engineering effort (both for ourselves and for community driver maintainers). From a purely theoretical POV, I do like the idea of disassembly better, but unfortunately we couldn't make this work and remain pragmatic.
- apendleton 13y agoI wonder if, for "if," you could just detect that your magical variable was being cast to a boolean, and run the function twice, once where it returns true, and once false, so you could exercise both branches. I guess this could get a little pathological if you had multiple conditionals and their nesting was really complicated, but I bet you could do simple conditionals...