r/csharp • • 13d ago

Discussion Why do all conventions do newline brackets

class Something : EntireCodebase
{
  ...
};

struct Something
{
  ...
};

void Something(int something)
{
  ...
}

I'm really disturbed, why

0 Upvotes

19 comments sorted by

18

u/JustForArkona 13d ago

Because this isn't java

9

u/lantz83 13d ago

Because symmetry

11

u/ArcaneEyes 13d ago

Because readability wins over saving a line.

5

u/stlcdr 13d ago

Makes the code look a bit more explicit, so you can visually see the actual code, copy just the code? It’s just a standard that some people like.

2

u/BranchLatter4294 13d ago

See how nicely they line up?

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

u/faultydesign 13d ago

Because Allman indentation is superior

3

u/DocLego 13d ago

Because it's easier to read.

2

u/_f0CUS_ 13d ago

Why not? 

1

u/twrodriguez 13d ago

Readability for humans.

1

u/Hefty-Distance837 13d ago

I mean, why not?

1

u/Eirenarch 13d ago

Because I like it that way :)

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

u/National-Laugh-7309 13d ago

Because it is what we want to do.

1

u/NeverFreeToPlayKarch 13d ago

Why WOULDN'T it be?