Read: Best C# IDEs for Developers What is Code Quality?Ĭode quality is the degree to which your code meets common industry standards for structure, formatting, and style. Since these tools run after compilation, rather than during it, they are able to examine more than just the syntax of your code they are able to look at all aspects of the assembly, including its physical structure and metadata as well as its logical behavior (also known as semantic analysis). These tools typically check for patterns of behavior that can be problematic at runtime. There are several tools that perform Static Code Analysis on compiled assemblies. The compiler’s job is to turn your C# code into an executable program, but it is also the Static Code Analysis engine that runs before compilation takes place and reports potential flaws in your code. Most often, this happens when developers compile your code. Static Code Analysis is a process that automatically checks your code for conformance to predefined standards. There's nothing wrong with disabling rules you don't want checked, but you should make it clear to developers why those rules were removed.Ĭreate a GlobalSuppressions.cs file in your project with the rules that have been turned off and why.In this C# programming tutorial, we will take a look at some of the most well-known code quality tools for C# developers, including NCrunch, CodeRush, StyleCopNDepend, and ReSharper/JetBrains. Is to document any rules you've turned off.Īll of these rules allow you to disable rules that you're not concerned about. Ratchet up your Code Analysis Rules until you get to 'Microsoft All Rules'įigure: Start with the Minimum Recommended Rules, and then ratched up. Run Code Analysis (was FxCop) with the default settings or ReSharper with Code Analysis turned onįigure: Run Code Analysis in Visual Studioįigure: The Code Analysis results indicate there are 17 items that need fixing Level 6 Is to use StyleCop to check that your code has consistent style and formatting.įigure: StyleCop shows a lot of warnings in this test project Level 5 Note: Document any rules you've turned off. Alt + Enter: Smart refactoring suggestionsįigure: ReSharper will show Orange when it detects that there is code that could be improvedįigure: ReSharper will show green when all code is tidy Level 2įigure: Code Auditor shows a lot of warnings in this test project.Alt + : Next/Previous Resharper Error / Warning.Tip: You can run through a file and tidy it very quickly if you know two great keyboard shortcuts: ![]() You want the files you work on to be left better than when you started. Get ReSharper to green on each file you touch. Combine this with Jetbrains' ReSharper and your code will be smell free.įigure: You wouldn't play cricket without protective gear and you shouldn't code without protective tools Level 1 Visual Studio has a great Code Analysis tool to help you look for problems in your code. No matter how good a coder you are, you will always miss things from time to time, so it's a really good idea to have a tool that automatically scans your code and reports on what you need to change in order to improve it. If everyone is following the same set of rules someone else’s code will look more familiar and more like your code - ultimately easier to work with. Whenever you are writing code, you should always make sure it conforms to your team's standards.
0 Comments
Leave a Reply. |