News for hackers. Stuff that matters.
Re:Stanford's CS 101 course uses Javascript by pgbovine on Saturday July 09, 2011 @11:08AM (#2745681)
the compiler also needs to figure out that getWidth() and getHeight() are pure.

but yes, i agree with you that for an intro class, students should focus on writing clear code and then optimizing for performance later.

Re:Stanford's CS 101 course uses Javascript by sheffield on Saturday July 09, 2011 @11:46AM (#2745748)
I find the efficient version much clearer, too. It extracts one layer of abstraction: a beginner may wondering, how can a variable being less than a function (a<func()), then find out, that the function returns a value, etc.

Two more lines worth it.

Re:Stanford's CS 101 course uses Javascript by danking00 on Sunday July 10, 2011 @10:04AM (#2747784)
I've been back and forth about how to respond to your comment. My initial reaction was "'func()' is a call and therefore returns an expression." Having thought about it, I don't really remember what my neophyte reaction would have been.
Re:Stanford's CS 101 course uses Javascript by kmfrk on Saturday July 09, 2011 @11:21AM (#2745708)
It shouldn't confuse students with optimization advice, but with the authority the lecture holds on malleable students, your asterisk should still be mentioned as an FYI for good measure.