The presentation summarizes the importance of writing maintainable code. It discusses code smells in brief and provides an introduction to software metrics.
is a measure of some property of a software system. Why? “Measurement is the first step that leads to control and eventually to improvement. If you can’t measure something, you can’t understand it.” (by James Harrington)
difficult. • Large entities indicate presence of various smells. LOC Lines Of Code NON Number Of Namespaces NOC Number Of Classes NOM Number Of Methods NOF Number Of Fields
class is a set of methods that can potentially be executed in response to a message received by an object of that class. • Larger the number of methods that can be invoked, the greater the complexity of the class. • If a large number of methods can be invoked in response to a message, the testing and debugging of the class becomes more complicated . RFC Response For Class
the comprehension difficult. • The deeper a class is in the hierarchy, the greater the number of methods it is likely to inherit, making it more complex to predict its behaviour. • Again, wide inheritance trees make the comprehension difficult. • A wide hierarchy indicates missing intermediate inheritance level that in turn may lead to code duplication. DIT Depth of Inheritance Tree NC Number of Children
with n methods M1, M2..., Mn. Let {Ij} = set of instance variables used by method Mi. There are n such sets I1 ,…, In • P = {(Ii, Ij) | (Ii ∩ Ij ) = ∅} • Q = {(Ii, Ij) | (Ii ∩ Ij ) ≠ ∅} LCOM = |P| - |Q|, if |P| > |Q| = 0, otherwise • High LCOM indicate the violation of the Single Responsibility Principle. LCOM Lack of Cohesion Of Methods
is a count of the number of other classes to which it is coupled. • Excessive coupling between object classes is detrimental to modular design and prevents reuse. The more independent a class is, the easier it is to reuse it in another application. • A measure of coupling is useful to determine how complex the testing of various parts of a design are likely to be. The higher the inter-object class coupling, the more rigorous the testing needs to be. CBO Coupling Between Object classes
quantitative measure of the number of linearly independent paths through a program's source code. • WMC – Sum of CC of each method in the class • The number of methods and the complexity of methods involved is a predictor of how much time and effort is required to develop and maintain the class. CCCyclomatic Complexity WMC Weighted Methods per Class
an innovative fix or a simple work-around, used for solutions that bend rules, or a resource that can be used as such, or a person who can solve a complicated issue.” …a work-around or hack जुगाड़
or more architecture components depend on each other directly or indirectly. • Unstable Dependency: This smell arises when a component depends on other components that are less stable than itself. • Ambiguous Interface: This smell arises when a component offers only a single, general entry-point into the component. • God Component: This smell occurs when a component is excessively large either in the terms of LOC or number of classes.
component realizes more than one architectural concern/feature. • Scattered Functionality: This smell arises when multiple components are responsible for realizing the same high-level concern. • Dense Structure: This smell arises when components have excessive and dense dependencies without any particular structure.
2. Install Designite from ‘Extensions and updates’ menu within Tools menu in Visual Studio. 3. Download any C# project (moderate size) 4. Open the project within VS and analyze it using Designite. 5. Tag each detected smell (well.. min 70; 2 of each kind). Tagging a smell means changing the smell status from ‘Identified’ to either ‘Refactor’, ‘Wrong’, or ‘Drop’ based on the semantics of the smell. 6. Cover all kinds of smells that are detected in your analysis
or a document with your user-id. Please note that user-id is not your department roll number. It is the id generated by the tool. You can find the id in this file: "C:\Users\<user name>\AppData\Roaming\Designite\.config\user.dat" 8. Excel sheet should have the following columns: <Smell name>, <Smell status>, <rationale – why you chose this smell status; one sentence per smell is enough> 9. Your grading depends on the smell tagging and the rationale you provide. 10. Send it by April 10, 2018.
if you want to understand any smell or you have any confusion related to the assignment. 12. To help you in this assignment, I will set up a machine with • Visual Studio 2017 installed • Designite installed • A few C# projects downloaded You may come to our lab and use the machine (well, don’t come together)