Skip to content

Principles

Costin Grigore edited this page Jan 13, 2023 · 68 revisions

There are principles, philosophies, paradigms, rules of thumb, adagios, mantras, best practices, patterns, anti-patterns, idioms, code smells etc. Some of them applies to the way things are (items and the relationship between them), some of them talk about a process or thinking process (how to move from one state to other). The first are called design principles, the later process principles.

Intro

  • Dumb Code Smart Structures
  • Null is not an Object
  • Array is not an Object

SRP - Single Responsibility Principle

  • enables composable features

PLS - Principle of Least Surprise

KISS - Keep It Simple

YAGNI - You aint gona need it

DRY - Dont Repeat Yourself

Fix bugs in one place, future reuse and improvements done in one place.

Fail Fast

Tell Don't Ask

Hollywood Principle - Don't call us We call you

OCP - Open Closed Principle

A part(component, class, api, schema, server) should be Open for extension, Closed for modification

LSP - Liskov Substitution Principle

DIP - Dependency Inversion Principle / IoC - Inversion of Control

POE - Premature Optimization is Evil

Premature Optimization is the Root of all Evil Optimization is done after a bug is filled with proof that the new code is improving the situation. Use a profiler Connected with YAGNI. Michael A. Jackson

  • The First Rule of Program Optimization: Don't do it.
  • The Second Rule of Program Optimization – For experts only: Don't do it yet.

See also Intro-to-Performance

Let it crash

On software systems in worst case scenario the systems should be able to crash/reboot and continue from where they left.

Uniform Access Principle

The uniform access principle of computer programming was put forth by Bertrand Meyer (originally in Object-Oriented Software Construction). It states "All services offered by a module should be available through a uniform notation, which does not betray whether they are implemented through storage or through computation".

Composition over Inheritance

Rules - future Principles?

  • Infinite Funds Syndrome (Cost of perfection might be an order of magnitude higher than good enough solution) - The assumption of an engineer that have infinite time & funds to do a perfect software(NASA, Nuclear, Aviation) when a good enough (at a fraction of the costs) will do just fine. Usually engineers that do not keep OCD under control.
    • Solution: focus on effort and impact (ROI - Return Of Investment) = Value Gained Or Impact / Effort Quantified in Both Resources and Time to have Perfect Solution (read The Nature of Software Development)
    • Maximum Impact is limited, Value is effort or negative costs and includes technical debt, lost opportunities and comes from all stakeholders
    • Effort could be infinite
    • image
  • Programming to Interfaces
  • NIHS - Not Invented Here Syndrome
  • DCSS - Dumb code, smart structures
  • FailFast
  • Elegant Objects
  • Defer Execution - do not compute what is not needed. See functional style.
  • Do not destroy information
  • No Code > Good Code > Incomplete Code > Wrong Code (good information > incomplete information > wrong information)
  • Conservative code (open close principle) Do write code to fix your problem/test and only your problem/test. All the other cases should be "fixed" only if they suffer from that bug.
  • Demeter Law
    • Parallel: E suficient sa se inteleaga ce inseamna Law of Demeter si impactul asupra designului. Exista forte care complica designul. Exista forte care il simplifica. Daca suntem constienti putem lua decizii mai bune. O paralela ar fi un sistem in care ai masina, jenti, cauciuc, vintil si aer/azot. Daca doar ca sa schimbi din aer in azot trebuie sa schimbi masina sau jentile … ai cam incalcat law of demeter.
    • PRO
    • CONS

Compare

Code smells

  • magical values

References

Table of Contents

Clone this wiki locally