javascript-patterns icon indicating copy to clipboard operation
javascript-patterns copied to clipboard

Define "trickyness" in for-loop pattern

Open bradym80 opened this issue 9 years ago • 3 comments

On line 35 of the for-loop pattern the following comment appears.

// optimization 3 - substitute i++withi = i + 1 ori += 1 to avoid excessive trickiness

Could you elaborate on "excessive trickiness"?

bradym80 avatar Apr 10 '15 13:04 bradym80

@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. :)

klomontes avatar Jun 15 '15 12:06 klomontes

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.

sumn2u avatar Jun 16 '15 00:06 sumn2u

Well, if i++ is too tricky I find it funny that in preferred 1 and 2 you use i-- :)

gianlucascoccia avatar Jul 01 '15 08:07 gianlucascoccia