<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt"><div dir="ltr"><div class="gmail_default" style>On Wed, Jan 2, 2013 at 10:58 AM, Daniel Jasper <span dir="ltr"><<a href="mailto:djasper@google.com" target="_blank" class="cremed">djasper@google.com</a>></span> wrote:<br>
</div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="font-family:arial,helvetica,sans-serif;font-size:10pt">
<div dir="ltr"><div>Well, this patch only consolidates the "int f() {}" and "int* f() {}" cases, so it is a step into the right direction. If we implement the line break you are suggesting, we should do so deliberately ;-).</div>
<div><br></div><div>clang-format currently formats like (assuming "bar" does not fit on the first line):</div><div><br></div><div><div class="im">
<div style="font-family:arial,sans-serif;font-size:13px"><font face="Courier">int </font><span style="font-family:Courier">foo(</span></div><div style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:Courier"> int bar,</span></div>
<div style="font-family:arial,sans-serif;font-size:13px"><font face="Courier"> int baz);</font></div><div style="font-family:arial,sans-serif;font-size:13px"><font face="Courier"><br></font></div><div style="font-family:arial,sans-serif;font-size:13px">
<font face="Courier">int *</font><span style="font-family:Courier">foo2(</span></div><div style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:Courier"> int bar);</span></div><div style="font-family:arial,sans-serif;font-size:13px">
<span style="font-family:Courier"><br></span></div></div><div style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial;font-size:small">I personally would prefer that over the other solution, but it is obviously a matter of taste (I didn't find anything in the style guide). </span></div>
</div></div></div></blockquote><div><br></div><div style>This got me thinking. Random thoughts follow, sorry if it's duplicating thoughts already had and written up by someone elsewhere.</div><div><br></div><div style>
I suspect it is useful to first imagine the extreme case:</div><div style><br></div><div style><font face="courier new, monospace">static inline</font></div><div style><font face="courier new, monospace">template <</font></div>
<div style><font face="courier new, monospace"> typename LongT1,</font></div><div style><font face="courier new, monospace"> typename LongT2></font></div><div style><font face="monospace">LongNameSpace1</font></div>
<div style><span style="font-family:monospace"> ::LongNameSpace2</span></div><div style><span style="font-family:monospace"> ::LongReturnType</span></div><div style><font face="monospace">LongNameSpace1</font></div><div style>
<font face="monospace"> ::LongNameSpace2</font></div><div style><font face="monospace"> ::LongFunctionName(</font></div><div style><font face="monospace"> LongNameSpace1</font></div><div style><font face="monospace"> ::LongNameSpace2</font></div>
<div style><font face="monospace"> ::LongParamType1</font></div><div style><font face="monospace"> LongParamName1,</font></div><div><font face="monospace"> LongNameSpace1</font></div><div><font face="monospace"> ::LongNameSpace2</font></div>
<div><font face="monospace"> ::LongParamType2</font></div><div style><span style="font-family:monospace"> LongParamName2) {</span><br></div><div style><font face="monospace"> // Some code...</font></div><div style>
<font face="monospace">}</font></div><div><br></div><div style>Now imagine each 'Long' name having too many characters to remove any line breaks in the above. I think this is the worst-case scenario[1], and at this point we should exceed 80-columns because there is just no hope....</div>
<div style><br></div><div style>From there, I see three interesting considerations:</div><div style>1) On which side of a separator do we break a line? for '(' and ',' we break after very consistently, but '::'? '&&'? There are mixed opinions here. I don't hold any particularly strong opinions that aren't already enshrined in convention (for '(', ',' and ';').</div>
<div style><br></div><div style>2) How much do we indent the next line? Starting from what position? This is easier when we can line up vertically a list. When the items in that list are too long to line up vertically, where do we start? I actually have some strong opinions here. They mostly center around ensuring that when we indent for two different purposes they get indented by a different amount visually. For example:</div>
<div style><br></div><div style><font face="courier new, monospace">SomeLongFunction(</font></div><div style><font face="courier new, monospace"> int SomeParam,</font></div><div style><font face="courier new, monospace"> int SomeOtherParam) {</font></div>
<div style><font face="courier new, monospace"> int MyLocalVariable;</font></div><div style><font face="courier new, monospace"> // ...</font></div><div style><font face="courier new, monospace">}</font></div><div style>
<br></div><div style>Is dramatically more readable to me than this:</div><div style><div><br></div><div><font face="courier new, monospace">SomeLongFunction(</font></div><div><font face="courier new, monospace"> int SomeParam,</font></div>
<div><font face="courier new, monospace"> int SomeOtherParam) {</font></div><div><font face="courier new, monospace"> int MyLocalVariable;</font></div><div><font face="courier new, monospace"> // ...</font></div><div><font face="courier new, monospace">}</font></div>
<div><br></div></div><div style><br></div><div style>3) How do we weight the different places that we might break a line when we don't require breaking on all of them. I think this is your question Jordan. I'm not sure where the balance point should be between breaking after the '(' versus before the function name, and I don't have terribly strong preferences here with one exception: I think I'd be willing to trade off almost any linebreak point *if* doing so allows us to move from a generic indent to a lined up vertical column. That would I think address your concern Jordan.</div>
<div style><br></div><div style>However, I think it would be good to get some of these extreme examples into the tests early, and start making sure we have good answers for #1 and #2 above, before we start really digging into #3. The reason is that personally I will misjudge the tradeoffs between the various options in #3 when one of those options happens to be laid out more poorly due to incomplete work on #1 and #2. When we can layout *all* of the line break candidates "perfectly" (as best we can figure out), then we can make a more informed decision on what the relative tradeoffs should be in #3.</div>
<div style><br></div><div style>-Chandler</div></div></div></div></div>