Code Quality Profile of Three Well-known C# Open-source Projects

Corefx , Roslyn , and MonoDevelop are widely-known open-source projects written in C#. Corefx contains the .NET Core foundational libraries, Roslyn implements the .NET compiler platform, and MonoDevelop is the cross platform IDE. We analyzed these projects to gain some insight about their code quality profile. We analyzed three versions of each project to see how these projects evolved from the code quality perspective.

The following table summarizes the selected snapshots of the projects:

Corefx Roslyn MonoDevelop
V1 Nov 10, 2014 Mar 18, 2014 Apr 30, 2010
V2 Aug 22, 2016 Sep 11, 2015 Apr 29, 2013
V3 Jan 1, 2018 Dec 12, 2017 Dec 28, 2017

We have excluded test-code from the analysis.

Size

All of these projects are large projects. The following graphs show their size in each considered version in terms of LOC (Lines of Code) and number of types.


Both the plots looks quite similar. It is interesting to note that for Corefx and Roslyn the average number of lines per type significantly reduces from version V1 to V3 – 162 to 100 (for Corefx) and 158 to 123 (for Roslyn). MonoDevelop shows almost consistent average lines of code per type across three version (111, 112, and 117).

Architecture smells

We detect seven architecture smells in all the versions of the considered projects. The detected smells are Cyclic Dependency, Unstable Dependency, Ambiguous Interface, God Component, Feature Concentration, Scattered Functionality, and Dense Structure. More information about these smells can be found on the FAQ page and more information about architecture smells can be found here.

The above figure shows that Cyclic Dependency and Scattered Functionality are the most commonly occurring architecture smells. On the other hand, Dense Structure and Ambiguous Interface occurs the least. Dense structure takes the whole codebase into consideration so it can be detected at most once in a codebase.

We can normalize these detected number of instances to get a consistent comparative perspective. Let us compute smell density (number of smells per 1000 lines of code) for the detected architecture smells.

The figure shows architecture smells density for each version of the analyzed projects. MonoDevelop seems to be suffering from architecture smells much more (by the factor of almost 3) compared to Corefx. However, the architecture quality has improved significantly in V3 of MonoDevelop compared to V2.

Design smells

Designite supports detection of 19 design smells – Unnecessary Abstraction, Imperative Abstraction, Multifaceted Abstraction, Unutilized Abstraction, Duplicate Abstraction, Deficient Encapsulation, Unexploited Encapsulation, Broken Modularization, Insufficient Modularization, Hub-like Modularization, Cyclically-dependent Modularization, Wide Hierarchy, Deep Hierarchy, Multipath Hierarchy, Cyclic Hierarchy, Rebellious Hierarchy, Unfactored Hierarchy, Missing Hierarchy, and Broken Hierarchy. A very comprehensive description of each of these smells can be found in this book. Description of the smells can be found on the FAQ page.

The following figure shows the detected abstraction smells in the analyzed projects. It is interesting to note that Corefx and MonoDevelop show a high number of duplication (shown by a high number of Duplicate Abstraction smell). On the other hand, Roslyn has relatively higher number of Unutilized Abstraction smells.

Similarly, the following figures show the detected encapsulation, modularization, and hierarchy design smells.

As we saw in the case of architecture smells, normalized number of detected smells can reveal interesting facts about the code quality of the analyzed projects. The following figure shows the smell density for all the analyzed versions. We observe that design quality of MonoDevelop is rapidly improving while design quality of Roslyn has deteriorated in the recent version compared to the considered previous version.

Implementation smells

Implementation smells, as their name suggest, are implementation level lowest granularity code smells. Designite supports detection of the following implementation smells – Long Method, Complex Method, Long Parameter List, Long Identifier, Long Statement, Complex Conditional, Virtual Method Call from Constructor, Empty Catch Block, Magic Number, Duplicate Code, and Missing Default. Details of these smells can be found on the FAQ page.

The following figure shows the individual implementation smell instances detected in all the analyzed versions. The table reveals that the Magic Number is the most frequently occurring implementation smell. Long Statement is another implementation smell that occur quite frequently in all the projects. On the other hand, Duplicate Code (duplication within a method body) and Empty Catch Blocks are the least frequently occurring smells.

It is interesting to note that Roslyn shows different implementation smell profile than the other two projects. Roslyn has significant higher number of Long Statements than other projects. Similarly, Roslyn shows significantly lower number of Magic Number smells.

Roslyn is exhibiting quite stable implementation smells profile while MonoDevelop’s profile has improved a lot. Corefx shows significant deterioration in code quality from implementation smells perspective from V1 to V2.

Conclusion

Looking at all the architecture, design, and implementation smells profiles, we can conclude that code quality of MonoDevelop is improving while Roslyn’s code quality is slightly deteriorating. Corefx seems quite stable from code quality perspective.

You can also analyze your C# codebase using Designite and understand it’s code quality profile.