[thelist] Coding Style
David Kaufman
david at gigawatt.com
Sat Apr 30 01:55:07 CDT 2016
Everyone:
I think it's great that human discussion has re-ignited spontaneously on
thelist lately. Welcome back!
I just read today about "Yoda Notation" on some blog. When asked to work
on someone else's javascript code, the blogged had came across all of these
ridiculous-style conditionals, consistently written like:
if ( true == isInitialized ) {
# do whatever...
}
or
if ( 0 == listLength ) ...
I'm sure all of us coders, of all stripes, can agree that consistently
putting the literal value on the left of a comparison operator like that
(and thereby being forced to put the l-value on the *right*, which just
adds insult to injury) seems like nothing other than a _deliberate_ attempt
to make one's code UN-readable! Right?
But it turns out this ridiculous coding style does not only have a name,
but an excuse! A justification, even! And a noble little green mascot, to
boot :-)
It's called Yoda Notation, and it's kind of a thin justification: the
reasoning is that it protects you from accidentally doing an assignment to
a variable, by mis-typing a single equal = sign, when you meant to merely
test the value stored in it with == or ===.
Once you know a thing's name you have google-power over it:
Yoda Notation
http://www.andrewpetermarlow.co.uk/personal/ranting_yoda.html
and of course every other google hit for ~that~ ...is either a meme or a
blog post that's just the setup for a punchline that's a meme:
-dave
More information about the thelist
mailing list