by itry · 12y ago · 0 comments
users=db.get("SELECT name FROM users WHERE group='admin'")
is more efficient and understandable then: users=[];
tmp=db.get("SELECT name,group FROM users")
for (i=0;i<tmp.count();i++)
{
if (tmp[i]['group']=='admin') users[]=tmp[i][name];
}Obviously you can make code both less efficient and less readable. But starting with code that a competent programmer has written, I find it seldom makes it more readable when you make it more efficient.
But who in their right mind would do the second one?
Oh abritishguy, I can assure you that the world is awash in such magical code snippets.Surely you jest. I don't know who, but their handiwork is everywhere.
for i = 1 to 100 if x = this do that and something with i else something else with i
easy to read, less efficient than: if x = this for i = 1 to 100 do that and something with i else for i = 1 to 100 do something else with i
from my experience, compilers usually dont hoist very well
edit: sorry, spaces didnt come out well