Depending on the situation, I'm not sure that less steps explicitly means more correct. Maybe more efficient, but even then I'm sure that's arguable depending on what the steps are.
Could you provide an example of how less steps explicitly makes a calculation more correct? I'm genuinely curious
It has nothing to do with number of steps, or more efficient (although ++i is more efficient than i++ in non-optimizing compilers).
It is a simplicity principle. This principle is the foundation of a lot of other philosophies and theories. For example, in the UNIX philosophy "Make each program do one thing well.". Or the simple statement "less is more".
Constructions which require less cognitive effort are easier to work with, and therefor result in less mistakes. This article basically point this out. So, both constructions can be correct, but the one which requires less cognitive effort is more correct.
Adding in the simplicity principle makes a lot of sense. In your original comment I was confused by the correlation of less steps and how correct a function is.
"the one which requires less cognitive effort is more correct."
This statement is what really answered my question. Thanks for taking the time to explain! That actually helped me better understand the simplicity principle better.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I alway use the prefix version, because it only does two things instead of three, and thereby more correct.
Depending on the situation, I'm not sure that less steps explicitly means more correct. Maybe more efficient, but even then I'm sure that's arguable depending on what the steps are.
Could you provide an example of how less steps explicitly makes a calculation more correct? I'm genuinely curious
It has nothing to do with number of steps, or more efficient (although
++i
is more efficient thani++
in non-optimizing compilers).It is a simplicity principle. This principle is the foundation of a lot of other philosophies and theories. For example, in the UNIX philosophy "Make each program do one thing well.". Or the simple statement "less is more".
Constructions which require less cognitive effort are easier to work with, and therefor result in less mistakes. This article basically point this out. So, both constructions can be correct, but the one which requires less cognitive effort is more correct.
A simple example.
Let's refactor that
Guess what, now it's wrong.
Adding in the simplicity principle makes a lot of sense. In your original comment I was confused by the correlation of less steps and how correct a function is.
This statement is what really answered my question. Thanks for taking the time to explain! That actually helped me better understand the simplicity principle better.