5 ms·
I personally find that I end up reading more lines of code than I need to. When scanning and I see If (condition) { perform_some_action(foo, bar, baz); }
by OriginalSyn 14y ago
I personally find that I end up reading more lines of code than I need to.
When scanning and I see
If (condition) { perform_some_action(foo, bar, baz); }
And I know condition is false I can ignore what follows but
perform_some_action foo, bar, baz if condition
I now have to stop and parse the entire line. But not only that, because it can appear at the end I need to parse every line to make sure I don't get caught by some if or unless. Short lines are easy sure but it's still annoying to me.
- ricardobeat 14y agoThat would make sense if you were executing code in your head, but if you're reading you want to read all of it anyway...
- epidemian 14y agoBut @OriginalSyn has a pont. If you are reading code because something is misbehaving on a given configuration and you read if (some condition that doesn't hold on that configuration) ... You can avoid everything inside that if statement if you know that's not important for the case you're considering.
- mayanksinghal 14y agoBut if we want to avoid it, we would be required to already know what's inside the parenthesis. If we already knew what's inside it, putting condition before helps more as in that case (1) Either it's true and you have to parse the block or (2) It's false and you just jump to the end of it.
- Jare 14y agoNot at all true, most of the time you are reading code with a specific goal or area of interest in mind, and thus are only interested in the subset of code related to that purpose.
- tjholowaychuk 14y agoyeah I agree here as well, postfix anything is quite annoying to read, especially so when chained, and the absence of parentheses makes this even more terrible