<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/94283>94283</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] Proposal for brace wrapping before the first statement
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
LMauricius
</td>
</tr>
</table>
<pre>
After pondering on the brace style that most suits me, I found the following rarely mentioned style:
```c++
if (condition)
{ printf("The condition is true");
return true;
} else
{ printf("The condition is false");
return false;
}
```
This style might look very unusual to most people, but it isn't unseen. Nowadays it is often called the Horstmann style, based on its author's name. There are a few books written with it, and it is mentioned on Wikipedia - [Horstmann Indentation_style](https://en.wikipedia.org/wiki/Indentation_style#Horstmann)
However, there isn't much tool support for it.
While the author himself has abandoned it, that was only because the author had to fight the formatting engines without support for it. I believe the reason why it's not more popular is because it is much harder to type, especially in editors where we usually get automatic indenting, and because the two most common styles are mentioned in many arguments on the 'best' style. On the other hand, I believe it is much easier to READ, and it offers the best of both worlds:
- It doesn't add a new line
- It makes the braces line up
With a formatting engine's automatic code modification, we could alleviate the difficulty in writing and retain the improvement in reading. This is obviously subjective, but many people including me would use this style as their favorite, along with at least one book author, as mentioned [here](https://horstmann.com/unblog/2010-06-28/braces.html)
# Needed changes
A boolean setting could be added in `BraceWrapping` called `BeforeOpeningStatement` with `true` as ts default. The comparison in code:
```c++
// true
if (condition)
{
printf("The condition is true");
return true;
} else
{
printf("The condition is false");
return false;
}
// false
if (condition)
{ printf("The condition is true");
return true;
} else
{ printf("The condition is false");
return false;
}
```
The way this could work is that for any braced block which gets wrapped, except for single line ones, the first statement will be put on the same line with the number of padding spaces equal to its usual indent size minus 1.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkVl1v28oR_TXUy8ACvfp-0IMdV4iBNinaAHkshuSQnHq5y-6HWPXXF7NLWXaSiwQXuE8X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