Laws of Software Engineering

(lawsofsoftwareengineering.com)

169 points | by milanm081 2 hours ago

25 comments

  • wesselbindt 2 minutes ago
    Two of my main CAP theorem pet peeves happen on this page:

    - Not realizing it's a very concrete theorem applicable in a very narrow theoretical situation, and that its value lies not in the statement itself but in the way of thinking that goes into the proof.

    - Stating it as "pick any two". You cannot pick CA. Under the conditions of the CAP theorem it is immediately obvious that CA implies you have exactly one node. And guess what, then you have P too, because there's no way to partition a single node.

  • Sergey777 6 minutes ago
    A lot of these “laws” seem obvious individually, but what’s interesting is how often we still ignore them in practice.

    Especially things like “every system grows more complex over time” — you can see it in almost any project after a few iterations.

    I think the real challenge isn’t knowing these laws, but designing systems that remain usable despite them.

  • RivieraKid 33 minutes ago
    Not a law but a a design principle that I've found to be one of the most useful ones and also unknown:

    Structure code so that in an ideal case, removing a functionality should be as simple as deleting a directory or file.

    • layer8 9 minutes ago
      Functionalities aren’t necessarily orthogonal to each other; features tend to interact with one another. “Avoid coupling between unrelated functionalities” would be more realistic.
    • danparsonson 13 minutes ago
      Features arise out of the composition of fundamental units of the system, they're not normally first class units themselves. Can you give an example?
    • kijin 23 minutes ago
      What's the smallest unit of functionality to which your principle applies?

      For example, each comment on HN has a line on top that contains buttons like "parent", "prev", "next", "flag", "favorite", etc. depending on context. Suppose I might one day want to remove the "flag" functionality. Should each button be its own file? What about the "comment header" template file that references each of those button templates?

      • jpitz 11 minutes ago
        I think that if you continue along the logical progression of the parent poster, then maybe the smaller units of functionality would be represented by simple ranges of lines of text. Given that, deleting a single button would ideally mean a single contiguous deletion from a file, versus deleting many disparate lines.
      • sverhagen 18 minutes ago
        Maybe the buttons shouldn't be their own files, but the backend functionality certainly could be. I don't do this, but I like the idea.
  • conartist6 57 minutes ago
    Remember that these "laws" contain so many internal contradictions that when they're all listed out like this, you can just pick one that justifies what you want to justify. The hard part is knowing which law break when, and why
    • AussieWog93 36 minutes ago
      DRY is my pet example of this.

      I've seen CompSci guys especially (I'm EEE background, we have our own problems but this ain't one of them) launch conceptual complexity into the stratosphere just so that they could avoid writing two separate functions that do similar things.

      • busfahrer 31 minutes ago
        I think I remember a Carmack tweet where he mentioned in most cases he only considers it once he reaches three duplicates
        • mcv 11 minutes ago
          I once heard of a counter-principle called WET: Write Everything Twice.
        • whattheheckheck 15 minutes ago
          Why 3? What is this baseball?

          Take the 5 Rings approach.

          The purpose of the blade is to cut down your opponent.

          The purpose of software is to provide value to the customer.

          It's the only thing that matters.

          You can also philosophize why people with blades needed to cut down their opponents along with why we have to provide value to the customer but thats beyond the scope of this comment

      • iwontberude 10 minutes ago
        Why do the have to be so smart but so annoying at the same time?
      • pydry 31 minutes ago
        DRY is misunderstood. It's definitely a fundamental aspect of code quality it's just one of about 4 and maximizing it to the exclusion of the others is where things go wrong. Usually it comes at the expense of loose coupling (which is equally fundamental).

        The goal ought to be to aim for a local minima of all of these qualities.

        Some people just want to toss DRY away entirely though or be uselessly vague about when to apply it ("use it when it makes sense") and thats not really much better than being a DRY fundamentalist.

        • layer8 25 minutes ago
          DRY is misnamed. I prefer stating it as SPOT — Single Point Of Truth. Another way to state it is this: If, when one instance changes in the future, the other instance should change identically, then make it a single instance. That’s really the only DRY criterion.
          • xnorswap 22 minutes ago
            I like this a lot more, because it captures whether two things are necessarily the same or just happen to be currently the same.

            A common "failure" of DRY is coupling together two things that only happened to bear similarity while they were both new, and then being unable to pick them apart properly later.

          • mcv 9 minutes ago
            That's how I understood it. If you add a new thing (constant, route, feature flag, property, DB table) and it immediately needs to be added in 4 different places (4 seems to be the standard in my current project) before you can use it, that's not DRY.
          • pydry 1 minute ago
            Renaming it doesnt change the nature of the problem.

            There should often be two points of truth because having one would increase the coupling cost more than the benefits that would be derived from deduplication.

    • ghm2180 53 minutes ago
      This is doubly true in Machine Learning Engineering. Knowing what methods to avoid is just as important to know what might work well and why. Importantly a bunch of Data Science techniques — and I use data science in the sense of making critical team/org decisions — is also as important for which you should understand a bit of statistics not only data driven ML.
  • fenomas 9 minutes ago
    Nice to have these all collected nicely and sharable. For the amusement of HN let me add one I've become known for at my current work, for saying to juniors who are overly worried about DRY:

    > Copy-paste is free; abstractions are expensive.

  • dataviz1000 1 hour ago
    I did not see Boyd’s Law of Iteration [0]

    "In analyzing complexity, fast iteration almost always produces better results than in-depth analysis."

    Boyd invented the OODA loop.

    [0]https://blog.codinghorror.com/boyds-law-of-iteration/

  • r0ze-at-hn 49 minutes ago
    Love the details sub pages. Over 20 years I collected a little list of specific laws or really observations (https://metamagic.substack.com/p/software-laws) and thought about turning each into specific detailed blog posts, but it has been more fun chatting with other engineers, showing the page and watch as they scan the list and inevitably tell me a great story. For example I could do a full writeup on the math behind this one, but it is way more fun hearing the stories about the trying and failing to get second re-writes for code.

    9. Most software will get at most one major rewrite in its lifetime.

  • Symmetry 19 minutes ago
    On my laptop I have a yin-yang with DRY and YAGNI replacing the dots.
  • dassh 8 minutes ago
    Calling them 'laws' is always a bit of a stretch. They are more like useful heuristics. The real engineering part is knowing exactly when to break them.
  • tmoertel 1 hour ago
    One that is missing is Ousterhout’s rule for decomposing complexity:

        complexity(system) =
            sum(complexity(component) * time_spent_working_in(component)
                for component in system).
    
    The rule suggests that encapsulating complexity (e.g., in stable libraries that you never have to revisit) is equivalent to eliminating that complexity.
    • stingraycharles 1 hour ago
      That’s not some kind of law, though. And I’m also not sure whether it even makes sense, complexity is not a function of time spent working on something.
      • tmoertel 40 minutes ago
        First, few of the laws on that site are actual laws in the physics or mathematics sense. They are more guiding principles.

        > complexity is not a function of time spent working on something.

        But the complexity you observe is a function of your exposure to that complexity.

        The notion of complexity exists to quantify the degree of struggle required to achieve some end. Ousterhout’s observation is that if you can move complexity into components far away from where you must do your work to achieve your ends, you no longer need to struggle with that complexity, and thus it effectively is not there anymore.

        • wduquette 18 minutes ago
          And in addition, the time you spend making a component work properly is absolutely a function of its complexity. Once you get it right, package it up neatly with a clean interface and a nice box, and leave it alone. Where "getting it right" means getting it to a state where you can "leave it alone".
  • ozgrakkurt 1 hour ago
    For anyone reading this. Learn software engineering from people that do software engineering. Just read textbooks which are written by people that actually do things
  • mojuba 1 hour ago
    > Get it working correctly first, then make it fast, then make it pretty.

    Or develop a skill to make it correct, fast and pretty in one or two approaches.

    • AussieWog93 40 minutes ago
      I recently had success with a problem I was having by basically doing the following:

      - Write a correct, pretty implementation

      - Beat Claude Code with a stick for 20 minutes until it generated a fragile, unmaintainable mess that still happened to produce the same result but in 300ms rather than 2500ms. (In this step, explicitly prompting it to test rather than just philosophising gets you really far)

      - Pull across the concepts and timesaves from Claude's mess into the pretty code.

      Seriously, these new models are actually really good at reasoning about performance and knowing alternative solutions or libraries that you might have only just discovered yourself.

      • mojuba 22 minutes ago
        However, a correct, pretty and fast solution may exist that neither of you have found yet.

        But yes, the scope and breadth of their knowledge goes far beyond what a human brain can handle. How many relevant facts can you hold in your mind when solving a problem? 5? 12? An LLM can take thousands of relevant facts into account at the same time, and that's their superhuman ability.

    • theandrewbailey 19 minutes ago
      Modern SaaS: make it "pretty", then make it work, then make it "pretty" again in the next release. Make fast? Never.
  • tfrancisl 49 minutes ago
    Remember, just because people repeated it so many times it made it to this list, does not mean its true. There may be some truth in most of these, but none of these are "Laws". They are aphorisms: punchy one liners with the intent to distill something so complex as human interaction and software design.
  • serious_angel 30 minutes ago
    Great! Do principles fit? If so, considering presence of "Bus Factor", I believe "Chesterton's Fence" should be listed, too.
  • WillAdams 1 hour ago
    Visual list of well-known aphorisms and so forth.

    A couple are well-described/covered in books, e.g., Tesler's Law (Conservation of Complexity) is at the core of _A Philosophy of Software Design_ by John Ousterhout

    https://www.goodreads.com/en/book/show/39996759-a-philosophy...

    (and of course Brook's Law is from _The Mythical Man Month_)

    Curious if folks have recommendations for books which are not as well-known which cover these, other than the _Laws of Software Engineering_ book which the site is an advertisement for.....

  • bronlund 19 minutes ago
    Pure gold :) I'm missing one though; "You can never underestimate an end user.".
  • James_K 5 minutes ago
    I feel that Postel's law probably holds up the worst out of these. While being liberal with the data you accept can seem good for the functioning of your own application, the broader social effect is negative. It promotes misconceptions about the standard into informal standards of their own to which new apps may be forced to conform. Ultimately being strict with the input data allowed can turn out better in the long run, not to mention be more secure.
  • vpol 43 minutes ago
  • grahar64 1 hour ago
    Some of these laws are like Gravity, inevitable things you can fight but will always exist e.g. increasing complexity. Some of them are laws that if you break people will yell at you or at least respect you less, e.g. leave it cleaner than when you found it.
    • stingraycharles 1 hour ago
      Lots of them are also only vaguely related to software engineering, e.g. Peter Principle.

      It’s not a great list. The good old c2.com has many more, better ones.

    • layer8 15 minutes ago
      Physical laws vs human laws.
  • d--b 56 minutes ago
    It's missing:

    > Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.

    https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule

    • tgv 21 minutes ago
      Shouldn't it also be able to read email? I think that was a law too.

      Anyway, the list seems like something AI scraped and has a strong bias towards "gotcha" comments from the likes of reddit.

  • threepts 36 minutes ago
    I believe there should be one more law here, telling you to not believe this baloney and spend your money on Claude tokens.
  • IshKebab 59 minutes ago
    Calling these "laws" is a really really bad idea.
  • _dain_ 1 hour ago
    I have a lot of issues with this one:

    https://lawsofsoftwareengineering.com/laws/premature-optimiz...

    It leaves out this part from Knuth:

    >The improvement in speed from Example 2 to Example 2a is only about 12%, and many people would pronounce that insignificant. The conventional wisdom shared by many of today’s software engineers calls for ignoring efficiency in the small; but I believe this is simply an overreaction to the abuses they see being practiced by penny-wise- and-pound-foolish programmers, who can’t debug or maintain their “optimized” programs. In established engineering disciplines a 12% improvement, easily obtained, is never considered marginal; and I believe the same viewpoint should prevail in software engineering. Of course I wouldn’t bother making such optimizations on a one-shot job, but when it’s a question of preparing quality programs, I don’t want to restrict myself to tools that deny me such efficiencies.

    Knuth thought an easy 12% was worth it, but most people who quote him would scoff at such efforts.

    Moreover:

    >Knuth’s Optimization Principle captures a fundamental trade-off in software engineering: performance improvements often increase complexity. Applying that trade-off before understanding where performance actually matters leads to unreadable systems.

    I suppose there is a fundamental tradeoff somewhere, but that doesn't mean you're actually at the Pareto frontier, or anywhere close to it. In many cases, simpler code is faster, and fast code makes for simpler systems.

    For example, you might write a slow program, so you buy a bunch more machines and scale horizontally. Now you have distributed systems problems, cache problems, lots more orchestration complexity. If you'd written it to be fast to begin with, you could have done it all on one box and had a much simpler architecture.

    Most times I hear people say the "premature optimization" quote, it's just a thought-terminating cliche.

  • milanm081 2 hours ago
    [dead]
  • Antibabelic 47 minutes ago
    Software engineering is voodoo masquerading as science. Most of these "laws" are just things some guys said and people thought "sounds sensible". When will we have "laws" that have been extensively tested experimentally in controlled conditions, or "laws" that will have you in jail for violating them? Like "you WILL be held responsible for compromised user data"?
    • horsawlarway 32 minutes ago
      At least for your last point... ideally never.

      Look, I understand the intent you have, and I also understand the frustration at the lack of care with which many companies have acted with regards to personal data. I get it, I'm also frustrated.

      But (it's a big but)...

      Your suggestion is that we hold people legally responsible and culpable for losing a confrontation against another motivated, capable, and malicious party.

      That's... a seriously, seriously, different standard than holding someone responsible for something like not following best practices, or good policy.

      It's the equivalent of killing your general when he loses a battle.

      And the problem is that sometimes even good generals lose battles, not because they weren't making an honest effort to win, or being careless, but because they were simply outmatched.

      So to be really, really blunt - your proposal basically says that any software company should be legally responsible for not being able to match the resources of a nation-state that might want to compromise their data. That's not good policy, period.

      • Antibabelic 18 minutes ago
        Incidents happen in the meat world too. Engineers follow established standards to prevent them to the best of their ability. If they don't, they are prosecuted. Nobody has ever suggested putting people in jail for Russia using magic to get access to your emails. However, in the real world, there is no magic. The other party "outmatches" you by exploiting typical flaws in software and hardware, or, far more often, in company employees. Software engineering needs to grow up, have real certification and standards bodies and start being rigorously regulated, unless you want to rely on blind hope that your "general" has been putting an "honest effort" and showing basic competence.