Thursday, June 16, 2016

Building Maintainable Software



Building Maintainable Software
Maintainability is not an afterthought, but should be addressed from the very beginning of a development project. Every individual contribution counts.
Some violations are worse than others. The more a software system complies with the guidelines, the more maintainable it is.

Write short units of code
Shorter units (that is, methods and constructors) are easier to analyze, test, and reuse.

REFACTORING TECHNIQUE:
EXTRACT METHOD
REPLACE METHOD WITH METHOD OBJECT

Write simple units of code
Units with fewer decision points are easier to analyze and test.

Dealing with Conditional Chains
IF-THEN-ELSE -> switch
-> map<>  -> Replace Conditional with Polymorphism

Dealing with Nesting

Write code once
Duplication of source code should be avoided at all times, since changes will need to be made in each copy. Duplication is also a source of regression bugs.
The Extract Superclass Refactoring Technique

Keep unit interfaces small
Units (methods and constructors) with fewer parameters are easier to test and reuse.
Limit the number of parameters per unit to at most 4.
Do this by extracting parameters into objects.
This improves maintainability because keeping the number of parameters low makes units easier to understand and reuse.

Separate concerns in modules
Modules (classes) that are loosely coupled are easier to modify and lead to a more modular system.
Avoid large modules in order to achieve loose coupling between them.
Do this by assigning responsibilities to separate modules and hiding implementation details behind interfaces.
This improves maintainability because changes in a loosely coupled codebase are much easier to oversee and execute than changes in a tightly coupled codebase.

Split Classes to Separate Concerns
Hide Specialized Implementations Behind Interfaces


Couple architecture components loosely
Top-level components of a system that are more loosely coupled are easier to modify and lead to a more modular system.
Achieve loose coupling between top-level components.
Do this by minimizing the relative amount of code within modules that is exposed to (i.e., can receive calls from) modules in other components.
This improves maintainability because independent components ease isolated maintenance.

Limit the size of modules that are the component’s interface.
Define component interfaces on a high level of abstraction. This limits the types of requests that cross component borders. That avoids requests that “know too much” about the implementation details.
Avoid throughput code, because it has the most serious effect on testing functionality. In other words, avoid interface modules that put through calls to other components. If throughput code exists, analyze the concerned modules in order to solve calls that are put through to other components.

Abstract Factory Design Pattern

Keep architecture components balanced
A well-balanced architecture, with not too many and not too few components, of uniform size, is the most modular and enables easy modification through separation of concerns.
Balance the number and relative size of top-level components in your code.
Do this by organizing source code in a way that the number of components is close to 9 (i.e., between 6 and 12) and that the components are of approximately equal size.
This improves maintainability because balanced components ease locating code and allow for isolated maintenance.

Keep your codebase small
A large system is difficult to maintain, because more code needs to be analyzed, changed, and tested. Also, maintenance productivity per line of code is lower in a large system than in a small system.
Do this by avoiding codebase growth and actively reducing system size.

Automate development pipeline and tests
Automated tests (that is, tests that can be executed without manual intervention) enable near-instantaneous feedback on the effectiveness of modifications. Manual tests do not scale.

Write clean code
Having irrelevant artifacts such as TODOs and dead code in your codebase makes it more difficult for new team members to become productive. Therefore, it makes maintenance less efficient.
Rule 1: Leave No-Unit Level Code Smells Behind
Rule 2: Leave No Bad Comments Behind
Rule 3: Leave No Code in Comments Behind
Rule 4: Leave No Dead Code Behind
Rule 5: Leave No Long Identifiers Behind
Identifiers that express multiple responsibilities or contain too many technical terms are always a violation of this rule.
Rule 6: Leave No Magic Constants Behind
Rule 7: Leave No Badly Handled Exception Behind
Always catch exceptions.
Catch specific exceptions.
Translate specific exceptions to general messages before showing them to end users.
Building Maintainable Software

Labels

Review (572) System Design (334) System Design - Review (198) Java (189) Coding (75) Interview-System Design (65) Interview (63) Book Notes (59) Coding - Review (59) to-do (45) Linux (43) Knowledge (39) Interview-Java (35) Knowledge - Review (32) Database (31) Design Patterns (31) Big Data (29) Product Architecture (28) MultiThread (27) Soft Skills (27) Concurrency (26) Cracking Code Interview (26) Miscs (25) Distributed (24) OOD Design (24) Google (23) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Interview Q&A (20) System Design - Practice (20) Tips (19) Algorithm (17) Company - Facebook (17) Security (17) How to Ace Interview (16) Brain Teaser (14) Linux - Shell (14) Redis (14) Testing (14) Tools (14) Code Quality (13) Search (13) Spark (13) Spring (13) Company - LinkedIn (12) How to (12) Interview-Database (12) Interview-Operating System (12) Solr (12) Architecture Principles (11) Resource (10) Amazon (9) Cache (9) Git (9) Interview - MultiThread (9) Scalability (9) Trouble Shooting (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Cassandra (8) Company - Uber (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Design (7) Interview Corner (7) JVM (7) Java Basics (7) Kafka (7) Mac (7) Machine Learning (7) NoSQL (7) C++ (6) Chrome (6) File System (6) Highscalability (6) How to Better (6) Network (6) Restful (6) CareerCup (5) Code Review (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Python (5)

Popular Posts