4 ms·
> Take a look at the following code and tell me which method looks better: That seems like a strawman to me. I would go with something like: function() {
by chriswarbo 10y ago
> Take a look at the following code and tell me which method looks better:
That seems like a strawman to me. I would go with something like:
function() {
nested_code() {
some_very_long_function_call(
long_argument_one, long_argument_two,
long_argument_three, long_argument_four,
);
}
}
- scrollaway 10y agoThat is no semantically no different to #2 so I'm not sure why you think it's a strawman seeing as you just agreed with me. While, like I said, there's reasons against alignment within lines, using tabs doesn't prevent you from doing it.
- chriswarbo 10y agoI meant that aligning columns is orthogonal to breaking up long lines; you can do either, both, or neither, so your example comes across as a strawman.
- scrollaway 10y agoThis isn't about breaking up long lines. The second indent style results in shorter lines, that is one of the various side effects which makes it superior. My example was meant to display that start-of-line alignment is generally a poor idea and there are better alternatives... which you seem to understand just fine.
- Stratoscope 10y agoBy 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.