One of the tips for jslint
tool is:
++
and--
The++
(increment) and--
(decrement) operators have been known to contribute to bad code by encouraging excessive trickiness. They are second only to faulty architecture in enabling to viruses and other security menaces. There is a plusplus option that prohibits the use of these operators.
I know that PHP constructs like $foo[$bar++]
may easily result in off-by-one errors, but I couldn't figure out a better way to control the loop than a:
while( a < 10 ) do { /* foo */ a++; }
or
for (var i=0; i<10; i++) { /* foo */ }
Is the jslint
highlighting them because there are some similar languages that lack the "++
" and "--
" syntax or handle it differently, or are there other rationales for avoiding "++
" and "--
" that I might be missing?
++
and--
operators. – Intro++
doesn't cause bugs. Using++
in "tricky" ways can lead to bugs, especially if more than one person is maintaining the codebase, but that's not a problem with the operator, it's a problem with the programmer. I didn't learn JS at university (because it didn't exist yet), but so what? I did do C, which of course had++
first, but that also gets a "so what?" I didn't go to university to learn a specific language, I went to learn good programming practices that I can apply to any language. – Oneiromancy/*jslint plusplus:true */
;^) Great links and well-meaning question, but I wonder how this dodged becoming a "closed, not constructive" candidate. – Illconditioned++
used properly is highly idiomatic. Forcibly using+=
instead will actually make the code less readable for any seasoned programmer because of that. – Syreetasyriaindex += 1; doSomethingWith(array[index]);
makes it clear what's happening when. – Barcellonawhile(idx<len && src[idx]!=null) { tgt[idx]=src[idx++]; }
is perfectly obvious to any non-novice programmer. Again, I say "hooey" to "don't use increment and decrement operators". – Maple