Five Laws of Software Everyone Should Know
Tags: programming, computerscience, development
Published: 2021-10-13 15:05:27

---
title: Five Laws of Software Everyone Should Know
published: true
description: Did you know there are laws of software just like there are laws of physics?
tags: programming,computerscience,development
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hzhhva6x128ujmphd21q.jpg
---

In no particular order, here are five Laws of Software everyone should know.

## The Law of Software Entropy

[The Law of Software Entropy](https://en.wikipedia.org/wiki/Software_entropy) is a metaphorical corollary to the [Second Law of Thermodynamics](https://en.wikipedia.org/wiki/Second_law_of_thermodynamics).

In a nutshell, it tells us that software rots over time. Even a stable piece of software that has few bugs will eventually deteriorate into a bug-ridden money-pit, if left alone. It could be due to security vulnerabilities found in dependencies or incompatibilities with new hardware, but entropy is an unavoidable property of software.

## Conway's Law

> Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the organization's communication structure.
>
> -- Melvin Conway, 1968

[Conway's Law](https://en.wikipedia.org/wiki/Conway%27s_law) is the fascinating observation that how a software organization splits out into teams is eventually mirrored in how the resulting software is structured. This has widespread implications for companies and open-source communities who need to tackle problems at scale but want to avoid duplicate work.

[Cross-functional software teams](https://en.wikipedia.org/wiki/Cross-functional_team) are one attempt to offset Conway's Law. A cross-functional team incorporates all necessary skillsets within one team, and therefore causes loose-coupling of the resulting application or service to the rest of the platform.

## Brooks's Law

[Brooks's Law](https://en.wikipedia.org/wiki/Brooks%27s_law) is Fred Brooks's famous observation that late software projects are only further delayed by adding additional developers.

There is a relationship with Conway's Law here since both laws are true from the same underlying cause: adding more people or teams to a software project always multiplies the amount of communication necessary to achieve each task. If you have n teams, n! communication paths exist. And since communication is the engine of product delivery, it is a case of "less is more."

## Hofstadter's Law

Of course, another related law is [Hofstadter's Law](https://en.wikipedia.org/wiki/Hofstadter's_law):

> It always takes longer than you expect, even when you take into account Hofstadter's Law.

I can't remember where I first read or heard it, but I was given the following formula for making estimates when I was a young programmer:

- Take the amount of time you think it will take (say two weeks)
- Double it (~~two~~ four weeks)
- Increase the unit of measure (four ~~weeks~~ months)

I believe this formula is an attempt to incorporate Hofstadter's Law into estimations.

## The Law of Demeter

[The Law of Demeter](https://en.wikipedia.org/wiki/Law_of_Demeter) is concerned with classic software engineering ideas like _encapsulation_, _loose coupling_ and _high cohesion_. It consists of three guidelines:

> - Each unit [of code] should have only limited knowledge about other units: only units "closely" related to the current unit.

> - Each unit should only talk to its friends; don't talk to strangers.

> - Only talk to your immediate friends.

A common example of a Law-of-Demeter-violation is as follows. Suppose you are at the store checking out. Does the clerk ask for your wallet or your money? If the clerk asked for your wallet and then took the money out for you ("user.getWallet().getMoney(amount)") then it's a classic violation of the Law of Demeter.

In a nutshell, this works out to the loose guideline that you should be wary any time there is more than one dot in any statement involving an object. Notice the two dots in "user.getWallet().getMoney(amount)."

Some have proposed that the "Law" of Demeter is really only a heuristic you can use to detect a [code smell](https://en.wikipedia.org/wiki/Code_smell), rather than being an actual "law." Nevertheless, it is commonly known as the "Law" of Demeter anyway.


And that's five of the more well-known laws of software.

> Photo by <a href="https://unsplash.com/@taypaigey?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Taylor Wilcox</a> on <a href="https://unsplash.com/s/photos/scrolls?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>