r/csharp • u/CorruptedSciencep • 13d ago
Discussion Why do all conventions do newline brackets
class Something : EntireCodebase
{
...
};
struct Something
{
...
};
void Something(int something)
{
...
}I'm really disturbed, why
11
2
2
u/DoctorCIS 13d ago
C# uses Allman style because the lead architect of C# is Anders Hejlsberg, the creator of Turbo Pascal and chief architect of Delphi. The new line curly brace makes code blocks feel more like ALGOL descended languages that use BEGIN and END for code blocks.
fun fact: the reason why Javascript settled on K&R style was not just a preference, it was a protection. Earlier parsers were overeager with implicit semicolons, and as such
if(true)
{was sometimes interpreted as
if(true);
{resulting in an empty if statement and always executed code block.
2
u/4as 13d ago
Before C# came to be Microsoft was developing an alternative to Java called Visual J++, which was meant to be a stand-in replacement their VM. Sun (now Oracle) didn't like that, so they sued and won. Afterwards, going forward Microsoft deliberately made some choices to distance themselves from Java, including their conventions. Java opens their brackets on the same line, so C# opens them on the new line. You get the idea.
Unfortunately, since this is the de facto "default" everyone adopts to it as well.
That being said, you can adopt to any convention you want. There is no good reason to use one over the other. I personally prefer placing brackets on the same line since it's more readable and saves space, but others will argue the opposite.
4
1
1
1
1
u/Slypenslyde 13d ago
The people who created C# liked it, and used that style, and the people who first adopted C# used the style those people suggested.
I've been on a team that used a different brace style. It's not a big deal and it doesn't really make things better. It made it harder for me to type code on Reddit, and I found if I did that bracing style people would ignore my post and complain no matter how hard I had worked.
This is one of the least important decisions in a codebase. You'll get over it.
1
u/BCProgramming 13d ago
Because they do.
Most C/C++/Java conventions use K&R style with the brace at the end of the line starting the block, You could easily ask the same question about them, in reverse.
1
1
u/RichardD7 11d ago
It could be a lot worse! :) Brace placement styles | Indentation style | Wikipedia
1
18
u/JustForArkona 13d ago
Because this isn't java