Coding Principles
Coding Principles
- Loose Coupling
- High Cohesion
- Change is Local
- It is Easy to Remove
- Rigidity ( A -> B -> C . something hardcoded in C )
- Fragility
- Immobility
- Viscosity of Design (Taking a shortcut and introducing technical debt requires less effort than doing it right.)
- Viscosity of Environment (skipping rigorous testing)
- Needless Complexity
- Needless Repetition
- Opacity
- Single Responsibility Principle (SRP)
- Open Closed Principle (OCP)
- Liskov Substitution Principle (LSP)
- Dependency Inversion Principle (DIP)
- Interface Segregation Principle (ISP)
- Classes Should be Small
- Follow Standard Conventions
- Keep It Simple Stupid
- Boy Scout Rule
- Avoid Multiple Languages in One Source File
- Keep Configurable Data at High Levels
- Don’t Be Arbitrary (Have a reason for the way you structure your code)
- Be Precise
- Make Logical Dependencies Physical
- Singletons / Service Locator
- Base Classes Depending On Their Derivatives
- Choose Descriptive / Unambiguous Names (Names have to reflect the entire functionality)
- Standard Nomenclature Where Possible
- no Encodings in Names (No prefixes, no type/scope information)
- maintain Consistency
- Use Explanatory Variables
- Prefer Dedicated Value Objects to Primitive Types (path type , instead of String , enclosing class)
- Poorly Written Comment
- Obscured Intent (Too dense algorithms that lose all expressiveness.)
- Obvious Behaviour Is Unimplemented
- Hidden Logical Dependency
- Methods Should Do One Thing
- Methods Should perform what is described by the name of the function.
- Avoid Method with Too Many Input Arguments
- Avoid Method with Too Many output Arguments (return object instead)
- Avoid Selector / Flag Arguments
- Avoid Inappropriate Static
- Variables and methods should be defined close to where they are used.
- Local variables should be declared just above their first usage ,depending on scope
- Nesting (should be more specific)
- Structure Code into Namespaces by Feature
- same feature together.
Eg :A feature may use another feature; a business feature may use a core feature like logging
- Avoid Dead Comment, Code
- Avoid Clutter
- Inappropriate Information
- Avoid Duplication
- Magic Numbers / Strings (Replace Magic Numbers and Strings with named constants)
- Catch Specific Exceptions
- Catch Where You Can React in a Meaningful Way
- Use Exceptions instead of Return Codes or null
- Fail Fast
- Avoid Using Exceptions for Control Flow
- Avoid Swallowing Exceptions
No comments:
Post a Comment