Does anyone change the Visual Studio default bracing style? - Is there a standard?

蓝咒 提交于 2020-01-14 06:56:33

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.




回答5:


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.




回答6:


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.



来源:https://stackoverflow.com/questions/4624286/does-anyone-change-the-visual-studio-default-bracing-style-is-there-a-standar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!