Coding Principles

Refactor to Pattern

  • Start from requirement
  • TDD: Write test first and iterate (help you to understand the requirements earlier)
  • Keep it simple stupid (KISS) whereas you need to:
  • Keep code separated based on responsibility and concern (SRP, Separation of Concern)
  • DRY (reuse)
  • Write clear interface and method signatures (Don’t make me think)
  • IoC - dependency injection makes test easier and swap out implementation in ease.
  • Abstract out the complexity - encapsulation/ information hiding.
  • Iterative design
  • Embrace changes

Minimize Coupling/ Maximize Cohesion

  • Avoid global variables
  • Code that has similar functionality should be found within the same component.
  • Any section of code (code block, function, class, etc) should minimize the dependencies on other areas of code. This is achieved by using shared variables as little as possible.

Open/Closed Principle

  • Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification
  • Avoid Premature Optimization
  • Don’t even think about optimization unless your code is working, but slower than you want. Only then should you start thinking about optimizing, and then only with the aid of empirical data.

Scaling Principles