Programming Principles

02/08/2025
Programming Principles

KISS (Keep It Simple, Stupid)

Simpler solutions are better; avoid unnecessary complexity.

Programming Principle KISS

DRY (Don’t Repeat Yourself)

Code duplication leads to maintenance nightmares. Abstract shared logic.

YAGNI (You Aren’t Gonna Need It)

Don’t build functionality until it’s actually needed.

SoC (Separation of Concerns)

Divide your code into sections, each responsible for a distinct aspect.

SRP (Single Responsibility Principle)

Each class/function/module should have one and only one reason to change.

OCP (Open/Closed Principle)

Software entities should be open for extension but closed for modification.

LSP (Liskov Substitution Principle)

Subtypes must be substitutable for their base types without altering program behavior.

ISP (Interface Segregation Principle)

Prefer many small, specific interfaces over one large, general-purpose interface.

Programming Principle ISP

DIP (Dependency Inversion Principle)

High-level modules should not depend on low-level modules; both should depend on abstractions.

Law of Demeter (LoD) / Principle of Least Knowledge

A module should not know the internal details of the objects it manipulates. “Only talk to your immediate friends.”

Composition Over Inheritance

Favor object composition rather than class inheritance to promote flexibility.

Fail Fast

Favor object composition rather than class inheritance to promote flexibility.

Tell, Don’t Ask

Instead of querying objects for data and then acting on it, tell objects what to do.

You Build It, You Run It

The team that writes the code should also be responsible for deploying and maintaining it.

Avoid Premature Optimization

“Premature optimization is the root of all evil.” Focus on clean, maintainable code first.

Principle of Least Astonishment

Code should behave in a way that least surprises other developers.

High Cohesion, Low Coupling

A module should do one job well (cohesion) and have minimal dependencies (low coupling).

Encapsulate What Varies

Isolate and encapsulate changing parts of the system to reduce ripple effects.

Clean Code

Code should be readable, well-organized, and self-explanatory.

CQRS (Command Query Responsibility Segregation)

Separate read and write operations for better scalability and clarity.