1433Re: one line if statements
- Aug 22, 2010Although I can see the OP's sentiment, the code enforcement that
JSLint employs tends to make us into better programmers. The idea of
dropping "superfluous" braces seems obvious at first, but it frequently
leads to tricky little errors. This shortcut is a legacy of C, IIRC, and
really should be consigned to the past.
Putting every block into braces (even if it's only 1 line) makes the
meaning obvious - and avoids those confusing "did he mean?" bugs.
Grab a copy of Code Complete by Steve McConnell
and you'll see this howler explained along with many more.
It's a great read.
- << Previous post in topic Next post in topic >>