Principles

Coding principles

The principles are meant to help you write effective code, by aiming at making the writer target discipline and purposeful writing.

  • KISS: Keep It Simple Stupid - It means you should be writing code as simple as possible. One of the rules of basic programming is to never get caught up in trying to be overly clever or showing off with a thick block of advanced code. If you can write a script in one line, write it in one line.
  • DRY: The Don't Repeat Yourself - Which means not repeating code, when writing code, avoid duplication of data or logic. If you've ever copied and pasted code within your program, it's not DRY code.
  • Open/Closed: means that you should aim to make your code open to extension but closed to modification. This is an important principle especially when releasing a library or framework that others will use.
  • Single responsibility: states that every class or module in a program should only provide one specific functionality. As Robert C. Martin puts it, "A class should have only one reason to change.”
  • YAGNI: means you should never code for functionality on the off chance that you may need something in the future. One of the most important principles of computer programming to learn is that you shouldn't try to solve a problem that doesn't exist.
  • Composition over inheritance principle states: objects with complex behaviors should contain instances of objects with individual behaviors. They should not inherit a class and add new behaviors.
  • Separation of Concerns: is an abstract version of the single responsibility principle. This idea states that a program should be designed with different containers, and these containers should not have access to each other. A well-known example of this is the model-view-controller (MVC) design.
  • Document your code.
  • Refactor and then refactor more.