I find the default bracing style a bit wasteful on line count eg...
function foo()
{
开发者_开发技巧 if (...)
{
...
}
else
{
...
}
}
would, if I was writing in JavaScript for example be written like...
function foo() {
if (...) {
...
} else {
...
}
}
...which I understand may also not be to peoples' tastes.
But the question(s) is/are do you turn off the VS formatting style and use your own rules? What is the opinion of this in the industry when many people are working on the same code-base? Is it better just to stick to the default just for simplicity/uniformity?
You need to have coding standards. There are no best standards. Standards such as having a brace on its own line or on the same line is a decision that one may take looking at comfort level of developers involved rather than on industry opinion (which will be typically divided).
But once standard is defined, you should adjust your tool to suit you. For example, you can change VS settings (Tools -> Option) as per your standards and then export those option groups as .vssettings file, keep it at central location/code repository and ask every dev to import it.
I'd stick with the default if you are working in a team and your code is under source control. If not you will end up having a hard time distinguishing the differences between real changes on check-ins and ones caused by the different position of the braces. In javascript from what I can remember there is good reason to use the braces as you have shown above. Douglas Crockford has a good article on why this is, I haven't added a link to the article because I couldn't find it right now, but it's worth having a look at his website none the less as it has heaps of interesting stuff on javascript.
I tend to stick to the default rules partly due to my own prefs but also because all projects I've taken part in (so far) has stuck to them.
You can find rules for new lines under Options/Text Editor/C#/Formatting/New Lines.
I used to fight this battle when I first started using c#. In the end I think 99% of people will use the default layout.
I bowed to the pressure of the crowd.
I always turn off the extra lines in the formatting settings, I like the more compact syntax.
I also change the font to Verdana, add a light gray background to string literals, remove bold on syntax pair matching (as it makes the code jump around), and set it to keep tabs instead of converting them to spaces. Other than that I find the default settings to work fine.
I don't think it is really about what VS default is, or even about what the industry standard is. The point that is most important is what does your team use, and what does the person paying the bills prefer. If your company doesn't actually have a set standard, you can look like a million bucks by suggesting that little gem. If source control is used, this standardization can save a LOT of noise when diffing things. This is however just my two cents.
精彩评论