Microsoft released the coding style forcible tool stylecop

Source: Internet
Author: User
Tags microsoft c

Http://developer.51cto.com/art/200806/76365.htm

Coding style is a topic that has been under heated debate for a long time. People are not only arguing over what encoding styles the team should follow, but also debate whether a standard encoding style should be established. At present, Microsoft has released stylecop, a forced tool for encoding styles they use internally. Microsoft's initiative will undoubtedly play a leading role.

Stylecop, also known as Microsoft C #Source codeAnalyzer (Microsoft Source Analysis for C #), which is similar to fxcop in usage, but takes effect on the sourceCode. In addition, it is similar to fxcop because of Microsoft's internal tools. After a certain degree of development, Microsoft felt that it was useful to others and was published. However, stylecop is less user-defined than fxcop.

The ultimate goal of source analysis is to allow you to generate elegant and consistent code, so that your team members and others who view your code can easily read it. To achieve this goal, source analysis does not allow excessive configuration of its rules. Source analysis uses a unified approach to handle code styles, layout, and readability rules. You may not agree with all the rules, or even find that some rules are not as expected. However, after a short adjustment period, most teams who use this tool within Microsoft can readily accept the rules required by source analysis, I even started to think that it would be hard to read if I didn't use this style to write code.

Jason allor claims that about 200 rules required by the tool are compatible with Visual Studio's default settings. Unfortunately, he forgot to mention that Visual Studio has six completely different default sets, most of which are in conflict with the tool.

This tool involves the following aspects:

· Support file content

· Debugging text

· Orchestration element header and document format in the file header
· Layout of elements, statements, expressions, and query clauses

· Line space

· Naming of elements, fields, and variables

· Braces, Parentheses, and square brackets

· Location of method parameters in method declaration or method call

· Spaces around keywords and operators

· Standard sequence of elements in a class

· Use of access Modifiers

· Use of built-in types

Applications in the blank ConsoleProgramIf you enable the "Keep Tabs" setting, 16 errors will be returned. Some rules are slightly clumsy. For example, the "using" indicator must be placed in the namespace rather than on the top of the file.

Someone is complaining about the tool's lack of support for correction. Dustin norman wrote:

When I run this tool on a small assembly, this tool requires me to manually modify 561 violation errors, however, it cannot automatically fix Errors for me without affecting the code semantics-This really causes me to crash!

The old tabs vs spaces debate [Note: whether the code indentation is implemented by tabs or by spaces] is also mentioned, and we cannot disable this rule. Nick Berardi wrote:

It's a joke. Tabs is not allowed. On the contrary, only spaces are allowed. This idea is terrible because it will damage the layout of the statement block. For example, a variable uses three spaces, while other variables use four. In any case, you should be allowed to disable meaningless rules such as Tab rules.
If these rules can be disabled, this tool is better. I know you will say they are good enough. However, I do not agree to use spaces instead of tabs. There is no logic at all. Perhaps it is only the first appearance of the VI editor that leads to a "war" between developers. I like to write my code using tabs, but it always warns me that each line of my code has tabs in it.

At the same time, Daniel Stolt also asked about VB:

It is always popular to provide some additional tools for. NET developers-but why only C? Mandatory rules of the code format are also required by VB developers.
Obviously, the VB code editor has some preliminary support for automatic formatting in the Process of indentation and spaces for keywords and operators, but it is not close to the effect supported by stylecop.

By the way, I fully agree with Nick Berardi's opinion on tabs vs spaces: what is the problem with using tabs? Is it better to press a button 4-5 times than to direct to a specific position? Or is there some benefit in saving 4-5 blank characters in the source code file?

There are indeed some problems in support of automatic correction. At present, there is no timetable for solving this problem.

Stylecop-Microsoft's style enforcement tool for C #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.