Re:Remove the ++ and –- operators
by nix0n on Thursday December 03, 2015 @06:11PM
(#10673429)
To me, ++ is the one obvious way to increment. I use for loops constantly and think of incrementation as a different thing from addition.
[ Parent
| on HN ]
Well yes, they are different from addition, but that still doesn't justify a special symbol for a special case of addition.
When your "increment by 1" is really just in the service of iterating over a set, then the natural, obvious way should be to use a separate idiom that abstracts the concept of iteration over that set, rather than dive into the details of how you get access to the next member. Which is what Python does: "for x in ...".
If the loop is not simply iterating over the set, but tweaking some value unpredictably and periodically checking, then there's nothing special about += 1 relative to += 2.
Why are you incrementing inside a Python for-loop? Are you familiar with ``enumerate``? In most situations, Python provides an iterator that tracks state for you and it's not necessary to increment state explicitly in the loop.
In higher level languages, loops are not about incrementing.