Programming principles and design patterns

List of programming principles aviable at Wikipedia 1.

DRY
Don’t Repeat Youself. Avoid writing the same code in multiple places. This principle make your code more maintainable when you need to change it.

Why repeating code is bad or can be bad?

  • If you need to change it, you have to change it in multiple places.
  • If you forget to change it in one place, you’ll have a new bug.
  • It’s more work to write it over and over again and maintain it.

KISS: Keep It Simple, Stupid

YAGNI: You Ain’t Going to Need It

SOLID
Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion.

Programming principles are required to write “good code”. If you follow them usually you receive good codebase which can be easily maintained and extended.

High-level principles:

  • Gathering problems and requirements is first step, and it’s important.
  • Architecture planning and discussion required to make decisions and deeply understand the problem.
  • Need to write maintainable code for people, DRY, KISS, YAGNI, need to avoid neurosis and excessive perfectionism.
  • Write simple self-documenting code that explains its logic, comments should be up-to-date and do not contain unnecessary information (explain what is not clear or why it was done that way):
    • I avoid deep abstractions and always prefer composition to inheritance or impurity.
    • I prefer flat data structures whenever possible.
    • I introduce external dependencies to a minimum (ideally without them at all).
    • I design modules with clear APIs, but almost never translate them into microservices.
    • To understand legacy code, I draw dependency graphs and sequence diagrams.
    • I write examples - lots of examples. Some of them are even interactive.
  • Several levels of testing, with the help of “tools” (debugger, linter, etc.) and automatic testing greatly help to detect bugs and issues.
  • Working with team, helping others and myself (documentation, training, reviews) significantly improve quality of any project.
  • I listen to the opinion of older comrades, experience is very expensive and useful.
  • I do refactor my code if something is unclear and needs to be improved.

Learning path

Footnotes

  1. Category:Programming principles - Wikipedia