3 ms·
Yes, you actually have to read the statement `i += 1` in order to know what it does. I don't see how that is an argument. It's barely longer than `i++`, in any
by throwaway999888 11y ago
Yes, you actually have to read the statement `i += 1` in order to know what it does. I don't see how that is an argument. It's barely longer than `i++`, in any case.
I could buy the argument if we were dealing with indexes or numbers where you had to read/hunt down occurrences of them to make sure they are what you expect. Like: make sure that a loop with a lot of indexes don't overincrement (out of bounds) or does something else that is wrong. But in this case the space isn't across a method, or a block. The space between the destination (i) and the increment number (1) is literally just 4 characters.
- AnimalMuppet 11y agoBut the point is that with ++, I don't have to look at all at the increment - I know what it is. The issue isn't how far away I have to look, it's that I have to look at all. (Or I don't look, and just assume that it's an add-one because that's what it always is, and then wonder why my loop doesn't work right.)
- dragonwriter 11y ago> the point is that with ++, I don't have to look at all at the increment Of course you do, otherwise you wouldn't know it was an increment in the first place.
- AnimalMuppet 11y agoWell, all right, my brain has to parse one fewer symbols. ++ is the equivalent of parsing +=, but there's no "1" or "j" or anything else that I have to parse in addition. (No pun intended, but I also didn't edit it out...)
- throwaway999888 11y ago> (Or I don't look, and just assume that it's an add-one because that's what it always is, and then wonder why my loop doesn't work right.) How often do your loops depend on incrementing a variable by one? In _Swift_ code.
- Nadya 11y ago>Yes, you actually have to read the statement `i += 1` in order to know what it does. Beginner here. Small detail... `i++` is read as `i = i + 1` and not `i += 1`. A small, but important distinction, especially for a beginner. `i += 1` is also parsed as `i = i + 1`. However for `i += n` it no longer parses as `i = i + 1` but rather `i = i + n` which is a step more difficult (and more powerful) than i++ which is always `i = i + 1`. However that is additional complexity not found in `i++`. (This is why I found `i++` easier than `i += 1`)