Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere to wrap a line of code, especially long argument lists?
    text
    copied!<p>What's your preferred way of wrapping lines of code, especially when it comes to long argument lists?</p> <p>There has been several questions relating to wrapping lines (such as <a href="https://stackoverflow.com/questions/268284/when-writing-code-do-you-wrap-text-or-not">When writing code do you wrap text or not?</a> and <a href="https://stackoverflow.com/questions/276022/line-width-formatting-standard">Line width formatting standard</a>), but I haven't been able to find one which covers where to wrap a line of code.</p> <p>Let's say we have a line of code that keeps going and going like this example:</p> <pre><code>int SomeReturnValue = SomeMethodWithLotsOfArguments(Argument1, Argument2, Argument3, Argument4); </code></pre> <p><strong>How should that be wrapped?</strong></p> <p>Here's a few ways I can think of, and some of their downsides:</p> <pre><code>int SomeReturnValue = SomeMethodWithLotsOfArguments(Argument1, Argument2, Argument3, Argument4); </code></pre> <p>I personally don't prefer that option because the formatting seems to visually separate the argument list from the method I am trying to call, especially since there is an assignment equals sign ("=") right above the orphanged arguments on the new line.</p> <p>So, for a while I went with the following approach:</p> <pre><code>int SomeReturnValue = SomeMethodWithLotsOfArguments(Argument1, Argument2, Argument3, Argument4); </code></pre> <p>Here, the arguments are all bundled together, all on the side of the method's first argument. However, one catch is that the argument list won't always line up in the second line onwards because of the number of spaces that the tab indents. (And typing extra spaces for formatting would be too time consuming.)</p> <p>An <a href="https://stackoverflow.com/questions/268284/when-writing-code-do-you-wrap-text-or-not#269025">answer</a> in the one of the previous questions suggested the following format:</p> <pre><code>int SomeReturnValue = SomeMethodWithLotsOfArguments( Argument1, Argument2, Argument3, Argument4 ); </code></pre> <p>I actually like this format, due to its visual appeal, but it also it does visually separate the arguments from the method that the list belongs to. Also, I prefer to have a single method call not take up too many lines.</p> <p>So, my question is, <em>without getting into the issue of preventing a code of line from getting too long in the first place</em>, <strong>how would you recommend wrapping lines of code?</strong> Specifically, <strong>where is a good place to break a line of code, when it comes to long argument lists?</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload