javascript-patterns
javascript-patterns copied to clipboard
Define "trickyness" in for-loop pattern
On line 35 of the for-loop pattern the following comment appears.
// optimization 3 - substitute
i++with
i = i + 1 or
i += 1 to avoid excessive trickiness
Could you elaborate on "excessive trickiness"?
@bradym80 I was wondering the same thing. My assumption was that i = i + i
is easier to understand since i++
requires some previous knowledge about this iterator. Not sure if there are some performance differences.
Anyway, I find i++
beautifully succinct and not tricky at all. :)
When you write these expressions as i = i + 1
it's clear what the intent of the programmer was and easier to find bugs in the code where as i++
prevents excess craftiness.
Well, if i++
is too tricky I find it funny that in preferred 1 and 2 you use i--
:)