Design Principles

What it is

Design principles are exactly that: principles that can guide you to crafting well-designed code. For example, the Don't Repeat Yourself (DRY) design principle says that the same code should not exist in multiple places. If, for instance, you have the same line of code duplicated a dozen times throughout your application, changing that line of code means hunting down and changing every single one of those instances, a tedious process that is easy to mess up.

Duplicated code is an example of a code smell, a sign that your code has a design issue and needs to be refactored.

Often, design principles (like those in the acronyms SOLID and GRASP) are taught in the context of Object-Oriented Programming (OOP), but many, like DRY, apply broadly across the spectrum of software development.

Why it matters

Writing code is a bit like driving a car while you are still putting it together. Requirements change, and software needs to grow and adapt with them. When code is poorly designed, it can become rigid and fragile. Making changes can become difficult when you have to do drastic rewrites to add new behavior, and small changes can introduce unforeseen problems.

A good metric of how well-designed code is is how easy it is to test.

Related guides

How to learn it

Naturally, software design is a broad and deep topic. Many of these principles will be covered in an introductory OOP course. Additionally, I believe that every developer should read the book Code Complete. If there’s one book to read as a young developer, this one is a strong contender.

Otherwise, wikipedia and google can get you pretty far. Read up on SOLID, DRY, separation of concerns, coupling and cohesion. Design Patterns are another closely related field.

As with a lot of things in software, just reading the definition of a pattern or principle isn’t going to help you really understand it. You’ll get better at design by writing a lot of code and applying these principles in context. There’s no shortcut.