News for hackers. Stuff that matters.
Re:2 is a code smell by Jach on Wednesday October 12, 2011 @05:08PM (#3104613)
It depends on what the language and compiler do for you, the elegant form may actually be faster than your supposed uglier-but-faster optimization. As always, time-test before and (if you've decided it's necessary) after optimizing. I remember reading a warning somewhere in the Clojure docs about how using (get x idx) is much faster than (nth x idx), I don't remember why though.
Re:2 is a code smell by NickPollard on Wednesday October 12, 2011 @06:16PM (#3104869)
This is of course true; ALWAYS profile the code before and after any optimizations, it is quite common for things not to act the way you'd expect (either because of the hardware, the compiler, or even other bits of code you're not aware of, which perhaps relies on certain assumptions).