A recent study (presentation, paper) conducted on close to 2000 open-source C# projects revealed that on average every C# class that we work with has approximately 2 design smells and 6 implementation smells. The study shows that unutilized abstraction and duplicate abstraction are the most frequently occurring design smells. Similarly, magic number implementation smell occurs most on average. In fact, there is one magic number smell in every 6 lines of code on average in the analyzed C# code.
What is the significance of these numbers? Code smells impacts maintainability of the software system; that means a higher number of smells will make a software system harder to understand, extend, and evolve. Consequently, a difficult to understand and difficult to extend software will reduce the productivity of the development team. Furthermore, the impact of smells are not limited to the maintainability of the software and productivity of development team, it has been shown that smells also lead to a buggy software (reliability) and impact negatively other quality dimensions.
What can we do about it? How can we avoid a large pile of smells to occur in our software? The answer to this question is twofold: 1) avoidance (by awareness and knowledge), and 2) removal (by detecting and refactoring smells). Many smells may occur in a software system at different granularities. A comprehensive taxonomy of smells can be found online that put together a wide variety of different kind of smells at one place.
In order to detect smells, we can use smell detection tools such as Designite. With Designite, we can detect smells at architecture, design, and implementation granularity within Visual Studio IDE. Designite’s Visual Studio 2017 and 2015 extensions are available from Microsoft marketplace, therefore we can install the extension using ‘Extensions and Updates’ option from ‘Tools’ menu of the IDE.
It is quite easy to analyze our C# projects using Designite. We just need to select ‘Analyze a solution’ option from Designite’s user interface. The tool will list all the C# projects in the loaded solution for us to choose which projects we wish to analyze. Once we select projects and click ‘Analyze’, the tool will analyze the source code and presents the summary of the analysis. We can also go in details either from the left side pan where project-wise details can be explored or from the main menu bar which is especially useful when we want to see the analysis results for all the analyzed projects.
A note of caution: Smells are indicators of potential maintainability issues. We need to treat the result of an analysis as a guiding mechanism and not as a rigid standard that our software must meet. We need to bring the context and experience into the picture and analyze each reported smell whether we should refactor it or not.