5 ms·
C# developers overwhelmingly prefer putting an opening brace { on it’s own line (query used) Putting it on it's own line seems like a waste of space to me and
by nawtacawp 9y ago
C# developers overwhelmingly prefer putting an opening brace { on it’s own line (query used)
Putting it on it's own line seems like a waste of space to me and doesn't contribute to the readability.
- mrighele 9y agoBeauty is in the eye of the beholder. For example I used to put the opening brace on a line of its own, mostly for simmetry reasons ( `{` in the same column as the relevant `}` ). By the way, after many years I had to change it for coding style reasons. Now when I look back to old code and I see that lonely `{` my reaction is "ewww", so I guess it is also a matter of habit.
- romanovcode 9y agoFor me it does.
- colejohnson66 9y agoIt’s the Visual Studio default. It definitely improves readability for me sometimes. Having empty lines makes it easier to read.
- partisan 9y agoIf I am not mistaken, Visual Studio automatically places an opening brace on the next line. When setting up coding standards, I asked my team not to fight Visual Studio. It generally has good auto-formatting functionality, but even more important is the uniformity and consistency of the code.
- shoover 9y agoOpening brace on a new line is the default, but VS has excellent granular settings in this area. I was tired of having different standards for C and C#, so at one point we switched our defaults and ran a utility to convert all our C# code. We use a new line for namespaces, classes, and methods and the same line for everything else. VS handles it flawlessly and we haven’t looked back. Thinking back, I have not seen any inconsistencies committed in that time. VS autoformat is that good, with braces and white space.
- omgtehlion 9y ago> a new line for namespaces, classes, and methods and the same line for everything else accidentally, we arrived to the same code style for both C# and C++...
- shoover 9y agoProbably accidental here, too, in that the C code was older and larger. There was no good answer for the question of why C# was different, so the change was made. The only downside would be if I worked on someone else’s project with different standards. I don’t think VS can figure out autoformat at the project level, like, say, python mode in emacs.
- jimktrains2 9y agoTo waste something there needs to be a finite amount of it in the first place. Considering the large number of coding standards that mandate the placement on a new line, tossing out readability because it doesn't matter to you seems short sighted.
- doodpants 9y agoThere is a finite amount of vertical space on one's screen, and thus a finite number of lines of code that can be displayed simultaneously without scrolling. Reducing the amount of scrolling that needs to be done to view the entire body of a method can itself be an improvement to readability.
- jimktrains2 9y agoI would argue that fitting the most lines on the screen as possible is not a noble goal. Whitespace is very important for readability.
- johnlbevan2 9y agoI used to agree, but since adopting the Allman style have found that in many cases it's very helpful in making code readable (especially if using an editor which doesn't provide any auto-format options). That said, some languages are impacted by style choice; e.g. JavaScript. Given many of us have to develop in multiple languages, it would be great to select a style supported by all languages (better would be if all languages supported all styles). https://stackoverflow.com/questions/12233999/is-it-true-that-i-should-use-kr-styling-when-writing-javascript https://stackoverflow.com/questions/12233999/is-it-true-that...
- mercer 9y agoPerhaps it makes copy/paste easier? I have a tendency to put the '[' of an array on a separate line for that reason, for example.
- mda 9y agoI know this is a matter of preference and habit, but I also cringe when I see this style, makes it less readable for me as well.
- emodendroket 9y agoAre we really going to derail this thread to argue about this? Everyone has their preferences but the most important thing is just picking a style and this is the one VS defaults to.
- bayonetz 9y agoI find it easier to visually match the start and end of the blocks that the brace pair defines. Having said that, my team uses the opening brace on same line style and that's fine too. Since I use an IDE, it doesn't matter much either way because It provides great features like block folding and auto highlighting of a matching brace. Don't understand why we spend so much time arguing about such low stakes stuff as this.