DEV Community

Adrián Norte
Adrián Norte

Posted on

Good code

I always hear developers say "We must write good code" or "That code is bad" but what is good code and what is bad code?

First of all, we are engineers and what is engineering? A very basic description is: To solve a problem using the state of the art at the lower cost.

Now we have to find where the costs are in software development, the costs are mainly divided in two: creation and maintenance. Being maintenance the one that is the biggest by orders of magnitude therefore we need to lower the cost of maintenance.

We have found that TDD and some others called "good practices" help make software maintenance costs lower by reducing refactoring risks or making a well structured class system. Therefore a codebase with a 90% code coverage and a very low cyclomatic complexity isn't good code because it have those but because thanks to those it keeps it's maintenance cost low.

With all of this said we can say then that good code is the one that is cheapest to produce (being maintenance inside the production cost) and a good engineer is the one that can produces good code.

What are your opinions about this?

Top comments (2)

Collapse
 
fpuffer profile image
Frank Puffer

In most cases this is true but there is at least one exception:

Not all code needs to be maintained. There is code whose purpose is fulfilled after being run once, like certain scripting, prototyping or data analysis stuff. Here the most cost effective code will probably not be good code.

Collapse
 
samuraiseoul profile image
Sophie The Lionhart

Yeah but in my experience, if you don't code like all code will need to be maintained, then you'll just be in pain later.

There have been more than a few times when I wrote a silly one off script, that then like 2 months later I needed again, but knew I would need to tweak it slightly, and had no idea what was happening because it go written poorly. Its not like writing it well takes THAT much longer either.