Which metrics are there and which tools exist to measure the SOLIDness of C# code? Or tools to indicate where the principles are violated most harmfully?
Scott Hanselman has an excellent article on NDepend. Also to see violation you can also use Code Analysis that comes with Visual Studio; you can use Code Analysis Policy Editor to choose rules.
You can use a static analysis tool (some are built into Visual Studio 2008 and above, professional editions and higher), or NDepend.
With NDepend, you can see how tightly coupled different classes are, what the cohesion of your codebase is like and more.
Related
How to profile a WPF application? I am a beginner C# developer, so I'm sure I would have made some mistakes/bad practices which I should alteast catch by profiling.
Is there a way I can see stack call of all the methods(only ones coded by me, not .NET library functions) and the duration of execution of each method?
Visual Studio includes a great profiling tool:
http://msdn.microsoft.com/en-us/library/z9z62c29.aspx
Another popular profiler for .NET is RedGate ANTS:
http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/
I've found RedGate ANTS easier to setup and use, but in the long run, I had better results with Visual Studio's profiler.
You can see time spent in just your methods, time spent in all methods, CPU time vs Wall time, and other useful metrics.
Just glancing around, this looks like a pretty good tutorial on the profiling tools of Visual Studio: http://www.geekzone.co.nz/vs2008/6265
It's for Visual Studio 2008, but it's the same concepts if you are using VS2010.
Beyond that, your probably need to ask something more specific.
As part of the SDK for Win7 .NET4 there is a profiler tool
"The WPF Performance Suite enables you to analyze the run-time behavior of your WPF applications and determine performance optimizations that you can apply. The WPF Performance Suite includes performance profiling tools called Perforator and Visual Profiler"
http://msdn.microsoft.com/en-us/library/aa969767.aspx
the core part of the bachelor thesis which I am writing right now is a plugin for a C# IDE that offers a few refactorings (it comes to more than simple refactorings but I want to keep it simple for the moment).
I've always been working with Visual Studio so far. However, I've heard that their AST access is rather uncomfortable.
Alternatives are MonoDevelop and SharpDevelop. Another way to work with Visual Studios AST would be to access it via a custom ReSharper Plugin.
Does anyone of you have experience in writing Plugins for any of those target applications? What do you think? I appreciate every advice and disadvice.
Thanks,
TH
An advantage of using MonoDevelop or SharpDevelop is that they're open-source, so you can be sure to have full access to the AST - you can go into the core and modify things, if necessary. Another advantage is that they're 100% managed code, so much easier to develop and debug. Plus, you're more likely to be able to get hold of core developers and ask them detailed questions.
If you're interested if working with MonoDevelop, I'd recommend you implement your refactoring directly in the existing Refactoring addin. We'd love to have more refactoring features :)
The codebase has been undergoing a bit of churn in master because we switched to a new AST and a parser based on the Mono C# parser, and the refactorings have not yet been ported over. I'd recommend you head over to our mailing list or IRC and ask some more specific questions there, so we can give you some more specific pointers.
I believe VS 2010 has very good native support for plugins using MEF. Here's a guide:
http://msdn.microsoft.com/en-us/library/dd885242.aspx
You can also use Devexpress DXCore, it's free with CodeRush Express.
The best AST access for refactorings is offered by NRefactory 5, a complete rewrite of the previous NRefactory version (which is used in both SharpDevelop and MonoDevelop).
For SharpDevelop we plan to use the new NRefactory in SharpDevelop 5.0; and MonoDevelop will also migrate to it eventually (MonoDevelop is already using the new AST, but not yet the new type system/semantic analysis).
The main goal for this rewrite was to:
Provide a rich AST with position information for every token, making refactorings easier to write
Improve the semantic analysis performance
Eliminate some bad design decisions from the previous version (IExpressionFinder, and how referenced assemblies are handled)
In the future, you might also want to look at Microsoft's Compiler-As-A-Service.
Also be sure to checkout ReSharper from http://www.jetbrains.com/resharper which is a plug-in for VS that adds many refactorings
I want to write a new templating language, and I want Visual Studio to "support" it. What I need to know is:
How do I parse my new language?
Given some code in my new template language, how do I translate it into HTML? Right now I'm using regular expressions to parse it token by token, but I don't think this is going to scale very well as the language gets more complicated, and there's no error checking. I've heard of ANTLR but never used it. Would that be the right tool for this job, or is there perhaps something simpler? Ideally I'd like to send any syntax errors to the error window with as much information as possible (line #, type of error) like other languages do.
How do I create a new file type for Visual Studio?
How do I get syntax highlighting?
Can I use the same parser I created in step 1, or is this something entirely different?
How do I get Intellisense?
I'd prefer to write my parser in C#.
I would take a look at another language that has already done the legwork of integrating with Visual Studio. A great example is Boo. The language and Visual Studio integration are open source. So you can take a look at exactly what they had to do.
Boo Language: https://github.com/boo/boo-lang
Boo Syntax Highlighting for VS2010 (VSX add-in): http://vs2010boo.codeplex.com/
Boo Language Studio (syntax highlighting for VS2008): http://boolangstudio.codeplex.com/
The Boo Syntax Highlighting for VS2010 includes some recommended links on its homepage, which I'll copy for easy reference:
Nice article about "classification" (syntax highligting) in VS 2010: http://dotneteers.net/blogs/divedeeper/archive/2008/11/04/LearnVSXNowPart38.aspx
Examples for VSX add-ins: http://blogs.msdn.com/vsxteam/archive/2009/06/17/new-editor-samples-for-visual-studio-2010-beta-1.aspx
Regarding the Visual Studio aspects, what you need is a "language service", which is the entity that handles colorizing, intellisense, etc. for a given file extension/type.
For an intro, see this article
And for a code sample see here
Regarding parsing, there are lots of technologies, and I won't offer an opinion/advice.
Beware, there is a fair amount of work involved, although in my opinion it is much more straightforward in VS2010 than in previous versions of Visual Studio to provide this kind of extension.
See also
Visual Studio 2010 Extensibility, MPF and language services
I wrote a VS Language Service using this article as my basis:
http://www.codeproject.com/KB/recipes/VSLanguageService.aspx
It wasn't too bad if you have a basic handle on Grammars.
There is a sample in the VS SDK that shows most of the features you are looking for.
I was using VS with own language and desperately needed a syntax highlight. I built mine based on this tutorial: https://mattduffield.wordpress.com/2012/07/31/writing-a-brightscript-syntax-highlight-extension-for-visual-studio-2010/
I know the tutorial is in VS2010. I made mine in VS2012 with no or very small hiccups. (also worked in VS2013) Recently I changed to VS2015 and the solution can be edited, built with no problem.
I found this very useful collection of recent samples for Visual Studio 2013 SDK:
http://blogs.msdn.com/b/vsx/archive/2014/05/30/vs-2013-sdk-samples-released.aspx
It also contains the recent version of the OokLanguage which sounds promising.
We used ANTLR 4 to parse our language which works like a charm and allows direct interaction with C# code. Can totally recommend it.
As mentioned in other answers, the most interesting code sample is the Ook language extension for the latest version of Visual Studio (2017 at the time of writing).
For VS 2015 see the sample in the VS2015 branch.
In order to install the SDK for 2015 or later, you need to rerun the VS setup. In 2015 it's called "Visual Studio Extensibility Tools Update 3".
I'm looking to find something along the lines of Checkstyle for Visual Studio. I've recently started a new gig doing .NET work and realized that coding standards here are a bit lacking. While I'm still a young guy and far from the most experienced developer I'm trying to lead by example and get things going in the right direction.
I loved the ability to use Checkstyle with Eclipse and examine code before reviews so I'd like to do the same thing with Visual Studio. Anyone have any good suggestions?
Another thing I'd be somewhat interested in is a plug-in for SVN that disallows check-in until the main coding standards are met. I do not want people checking in busted code that's going to wind up in a code review.
Any suggestions at this point would be great.
Have you tried StyleCop?
http://code.msdn.microsoft.com/sourceanalysis
Note: This's been moved to https://github.com/StyleCop
Take a look at resharper.
We use StyleCop to enforce our coding standards. It is free and integrates nicely with Visual Studio
What you're looking for is called Static Code Analysis.
FxCop is one option. I think Resharper can check this kind of thing as well.
Here are some of the great tools you can use
FxCop is a code analysis tool that checks .NET managed code assemblies for conformance to the Microsoft .NET Framework Design Guidelines
ReSharper is a refactoring and productivity plugin by JetBrains that extends native functionality of Microsoft Visual Studio .NET 2003, 2005 and 2008.
StyleCop is a free static code analysis tool from Microsoft that checks C# code for conformance to StyleCop's recommended coding styles and a subset of Microsoft's .NET Framework Design Guidelines
ref: http://blogs.msdn.com/fxcop/
Have you had a chance to review StyleCop
If you are looking for a long term supported version, I would recommend to look to Roselyn analyzers. They are the native support for Static Code Analysis with pre-configured rules, custom configs, and allow extensions.
According to the docs: “.NET compiler platform (Roslyn) analyzers inspect your C# or Visual Basic code for code quality and style issues.”
https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview
I'm looking into Productivity tools for developing in C# / Visual Studio 2008 (pr0) and developing web apps (not using MVC).
Anything from favourite visual studio shortcuts to external tools and plug-ins.
Ctrl+. is one of my favorites. It adds a Using statement for the current class if you don't already have it.
For example if you have this:
Regex
And you hit Ctrl+.. Visual Studio will add
using System.Text.RegularExpressions;
to the top of your file.
I also like Code Rush and Refactor Pro from DevExpress.
A very interesting one that was just announced is Telerik's JustCode. It's basically a new refactoring tool (such as Resharper and CodeRush, also very good productivity improvement tools), but also handles Javascript in web projects.
Tools like these can dramatically improve the amount you can get done in a short amount of time.
ANTS Profiler from Red Gate helped our company find a lot of bottlenecks in our C# code.
Reflector from Red Gate PowerCommands visual studio add-in any form of Grep
We've just started using GhostDoc which is pretty useful for quickly generating outlines of comments especially when you're generating your documentation from your XML comments. It's definitely saved me some time.
its not a tool but a big reference chart - you can print it out and hang it on at your work area, to refer quick key bindings http://www.microsoft.com/en-us/download/details.aspx?id=7162