4 ms·
Probably this is only "semantics", but I find these two quite similar :). I like the idea of having the query being executed only when needed, but I'm not sure
by alexpopescu 14y ago
Probably this is only "semantics", but I find these two quite similar :). I like the idea of having the query being executed only when needed, but I'm not sure that's always possible (or optimal with large result sets).
thanks,
alex @ rethinkdb
- StavrosK 14y agoSure, they are almost identical, but one doesn't need .run() :) I don't see how it wouldn't be optimal, since lazy evaluation is a superset of eager evaluation (you can invoke it whenever you want).
- alexpopescu 14y agoBoth solutions are lazy. While ReQL requires .run(), the Django ORM requires you to do 'list()' (or probably other form of iterator over it). I'd say the only difference is that one is explicit and the other one is implicit.
- shrughes 14y ago.run() is also bad. What connection is it being run on? The most recently opened connection? In a global variable somewhere? For anything larger than a short script, you should use query.run(conn), or conn.run(query).
- InAnEmergency 14y agoYes, especially in web applications. Found that out the hard way.
- coffeemug 14y agoLaziness typically implies something isn't evaluated until you need the data (e.g. you coerce it to a native language data structure, or you need to print it, or write it to a file or network). So saying list(query) lazily evaluates the query, while saying query.run() is a more strict (explicit) evaluation model. I actually think strict is better here, but that's a different discussion altogether :)