3 ms·
By definition, scrollaway's example is not a strawman, because the first version matches the way I've seen code formatted very many times. (I wonder if this wh
by Stratoscope 10y ago
By definition, scrollaway's example is not a strawman, because the first version matches the way I've seen code formatted very many times.
(I wonder if this why your comment got downvoted? FWIW, I upvoted you for engaging in the discussion.)
Personally, I would do his second example like this:
function() {
nested_code() {
some_very_long_function_call(
long_argument_one,
long_argument_two,
long_argument_three,
long_argument_four,
);
}
}
In other words, once I get to the point of splitting up the call into multiple lines, I generally split all the arguments onto their own lines.
Now all the arguments are lined up with each other, as they are in your example. This matches how I format multiline statement blocks: if I'm splitting the code to multiple lines, then I split it consistently on each argument. This way I don't have to worry about how many arguments fit on a single line.
Of course I'm not entirely consistent about this. :-) Take a function like CreateFile() in the Windows API. It has so many parameters, and you're likely to pass in NULL or 0 for so many of them, that it makes sense to bunch them up a bit to not use so many lines.
But even then I wouldn't start adding extra spaces within a line to make vertical columns out of it.