No Silver Bullet — Essence and Accidents of Software Engineering
Fred Brooks
This is one of the famous quotes by Turing Award-winning Fred Brooks. The complexity of software is tough to define. It is a measure of your program which is partially about the size and partially about understandability (clarity) of the code. A complex code does hinder on the habitability of your code.
Accidental vs. Essential
Fred Brooks, the author of the paper entitled "No Silver Bullet — Essence and Accidents of Software Engineering", distinguishes between two types of complexities: accidental and essential.
As the name itself suggest accidental complexity is about pieces of your program that are largely avoidable. For example: if an entity can retain its identity without some attributes than those attributes result in accidental complexity. It may be possible to abstract some of them into an abstract class, but do avoid leaky abstractions.
Great technique for getting rid of accidental complexity is checking whether something hasn't been already done in this area i.e. reuse software. Brooks also pointed out right language makes a heck of a difference i.e. if you can use Java, do Java and not VB6 or C++ (where you have to worry about deallocating memory etc.)
Essential complexity is the necessary things which are needed to solve the problem. It usually arises due to unknowns and uncertainties. These can be addressed by rapid prototyping.
Measuring Complexity
Cyclomatic Complexity
Cyclomatic Complexity counts the number of independent paths in (or part of) your program. ABC method can be used to approximate complexity:
- Assignment
- Branches
- Conditions
In a class, method or the entire program, count the number of assignments, branches and conditions and use
Getting Simple
There are few rules of thumb to help get to simply the software:
- Favour shorter methods
- Favour functional style to loops
- Favour method calls to conditions
- If reusing parts of the code, check if creating a new abstraction is a suitable approach to reduce complexity and duplication