Tag: TDD

  • Chris’ First Rule of Software Development

    Chris’ First Rule of Software Development

    I once worked with a team that, for some reason, valued complexity. It seemed like their egos were tied directly to how hard something was to do. If something was hard and they completed it then that proved that they were smart 🤷‍♂️? I tried multiple times to introduce the idea of simplicity to them, but it never stuck.

    In response to the above, I developed a simple rule that I follow and I tell every team I work with and every engineer that I teach and it is:

    “If what you are doing is getting more and more complicated, then you are heading down the wrong path. Conversely, if what you are doing is getting simpler, then you are probably headed in the right direction.”

    Me

    That’s it. If what you are doing is hard, then stop, think, maybe backup and figure out what you’re missing. However, if what you are doing is simple, easy to reason about, and straight forward, then keep going.

    You will notice that the complicated path is phrased as an absolute whereas the simple path is less certain. That is because we have to take into account that

    For every complex problem there is an answer that is clear, simple, and wrong.

    H. L. Mencken

    Thankfully, the opposite is also true. There is a solution that is clear, simple, and correct. And, as engineers, this is the solution that we should be constantly aiming for.

    In everything we work on there are two kinds of complexity; Inherent Complexity and Accidental Complexity.

    Inherent Complexity

    This is the complexity that is part of the problem. Think calculating compound interest. There is nothing that can be done to simplify the calculation, it is just complex. However, we can still isolate that complexity, trim it down, and find the simplest form of it to initially implement.

    Accidental Complexity

    This is the complexity that we as developers introduce to the code base by not taking time to refactor or problem understand the problem we are trying to solve. We go for the easiest implementation, shove the new code into place and then call the problem solved. And we don’t take the time to be professionals. I always use the analogy that this is like going to the doctor and finding out that they couldn’t be bothered to sterilize their instruments before seeing you.

    This idea of simple is reinforced by the second rule of Test-Driven Development (TDD). Get the test to pass by implementing the simplest thing that will work. And by the third step of refactoring. If we make a mess, we also need to take the time to clean it up. We need to pride ourselves on the simplicity of our solutions and not how hard it was to implement. This isn’t to say that refactoring is simple.

    “…for each desired change, make the change easy (warning: this may be hard), then make the easy change”

    Kent Beck
  • Thoughts on Static Typing

    Thoughts on Static Typing

    I don’t think I am the only person out there that has noticed a trend in the software engineering community away from dynamically typed languages like Ruby to statically typed languages like TypeScript, Java, and Kotlin. What I don’t entirely understand is why. While statically typed languages do provide some nice tooling and work well with IDEs and VS Code, I don’t think that’s the real reason that people are adopting them.

    I think the current love for Java, TypeScript, etc., is based on a myth and misunderstanding. It’s based on the idea that if the code compiles then “it will just work” The idea that if there are no compile time errors, then the engineer must have gotten it right.

    We are at a point where we have Rails and JS applications that are in the hundreds of thousands of lines of code. And the engineers on those projects are having problems. And they think that the solution is to start using, or to introduce, static typing. Just look as Shopify.

    But will static types solve magically make the code base more understandable and easier to reason about? I don’t think so. Contrary to current belief, it is just as easy to create spaghetti code in Java as it is in Ruby. I personally think the problem is not the type system but the engineers and the code they have created.

    Most code bases I have worked on where engineers are asking for static typing either have no tests or very few tests and the engineers do not use TDD and do not refactor. They have spent years creating terrible code and they are suffering the consequences of that. However, instead of cleaning up their code and adding tests, they want a silver bullet and they look at introducing static types. They think the extra tooling you get and the compile time errors will solve their really bad engineering habits and allow them to, once again, extend the code at speed.

    For me, this just doesn’t make sense. It’s similar to wrapping a failing building in scaffolding to help hold it up instead of repairing or replacing the building. It will work for a while, but the building will eventually fall down.

    If you want a code based that you can extend and maintain in a few years your team needs to be doing TDD with constant refactoring. You need to be following Robert Martin’s Boy Scout rule and clean up the code that you are working in and leave it cleaner than when you arrived. And this includes adding tests. This is the only way to ensure you have code that you can reason about, understand, and continue to work on.

Copyrighted Image