Coding principles

There are some rules / principles that should be followed independently from language you are using:


  • S: SRP - Single Responsibility Principle: one class/function should be responsible for one feature only
  • O: OCP - Open/Closed Principle: code should be open for extensions, but closed for changes
  • L: LSP - Liskov Substitution Principle: classes derived from base class/interface should not break interface (example - do not throw "function forbidden!")
  • I: ISP - Interface Segregation Principle: write interfaces so narrow that client code does not include function it doesn't need
  • D: DIP - Dependency Inversion Principle: depend on interfaces, not concrete classes

DRY - Don't Repeat Yourself

Simply put - do not repeat code more than once (longer than few lines).

KISS - Keep it simple, stupid

Do not complicate things if it is not needed. Use "Occam razor" rule if you have doubts.

YAGNI - You ain't gonna need it Do not write code that is not required now. If you will need to change it in the future - do it in the future (it's called R-E-F-A-C-T-O-R-I-N-G).