Yes, the main issue is mutability. The ++ operator is actually a hidden assignment. In most modern languages there are few use cases for incrementing variables, mainly because they provide better ways for looping over collections. However I sometimes have to maintain legacy C code where I don't want to miss ++ in for loops.
I believe that += is only slightly better when it comes to copy/paste errors. You can also do this (at least in C++ and Java - not sure about JS):
Yes, the main issue is mutability. The
++
operator is actually a hidden assignment. In most modern languages there are few use cases for incrementing variables, mainly because they provide better ways for looping over collections. However I sometimes have to maintain legacy C code where I don't want to miss++
infor
loops.I believe that
+=
is only slightly better when it comes to copy/paste errors. You can also do this (at least in C++ and Java - not sure about JS):But it looks weird and will hopefully be noticed soon.