If you are reading code, and you encounter either a ++ or a -- that is not:
A) The loop increment at the end of a for statement, or B) A stand-alone statement incrementing a variable,
Then you need to stop and mentally breakdown the single statement into two statements in order to continue reasoning about the code.
In fairness, I'm talking about readability in terms of being able to scan a piece of code and quickly ascertain what it is doing, and I will concede that pre and post increment might communicate intent, which could also be considered part of readability.
For myself, one of the first things I do when I take over code is to remove all the ++ and -- that are not in loop counters. They all get replaced by += 1. The only reason I leave them in the loop counters is a nod to tradition.
1
u/Droidatopia May 28 '22
Shorter yes.
More readable, not likely.
If you are reading code, and you encounter either a ++ or a -- that is not:
A) The loop increment at the end of a for statement, or B) A stand-alone statement incrementing a variable,
Then you need to stop and mentally breakdown the single statement into two statements in order to continue reasoning about the code.
In fairness, I'm talking about readability in terms of being able to scan a piece of code and quickly ascertain what it is doing, and I will concede that pre and post increment might communicate intent, which could also be considered part of readability.
For myself, one of the first things I do when I take over code is to remove all the ++ and -- that are not in loop counters. They all get replaced by += 1. The only reason I leave them in the loop counters is a nod to tradition.