Breaking those long lines of code into smaller, grouped ones, with a clear consistency on where different types of elements are placed, is a small and efficient step towards improved readability.
Consider the code example below. There are two calls, five arguments, and three levels of nesting. However, that’s not what we get from the looks of it. We need to spend time visually parsing it and group the parts in different categories, not to mention that scrolling is required to even read the whole thing.
Note the form of this code, leaving the actual code aside. No clue, whatsoever.
From now on
We want to clearly see, without knowing the code, what is:
- A function call
- A function’s arguments
- Part of what
For that, we need to separate calls from arguments by placing the arguments in a new, indented line:
Where now the form of this code says it all, whatever the actual code is:
The advantages are not just structural, visual, or subjective . Note that now the addition, removal, or modification of a function argument will be shown in a separate git diff line, instead of ending up with a single git diff line that mixes up all of the different changes made to your project.