DEV Community

Discussion on: What is bad code?

Collapse
 
curtisfenner profile image
Curtis Fenner • Edited

Bad code is code that costs more than it needs to.

Some of the ways that code costs us is when:
It's too slow/uses too many resources, it does the wrong thing, it's too hard to understand, it's too hard to change, or it's too hard to delete.

Code is bad code (and not merely solving a complex problem) when there is a way to (re)write it that would be faster, does the right thing, is easier to understand, is easier to change, and is easier to delete.

Collapse
 
stereobooster profile image
stereobooster

It's too slow/uses too many resources

Who cares if it still produce more money than it spends? (There are people which will ask this question)

it does the wrong thing

Assuming we know what the right thing is. I mean we can know some portion of requirements. The question is: which portion is it 20%, 50%, 80% (based on Pareto principle)? To makes sure software is doing 100% correct thing we need formal specification and verification, which is hard.

it's too hard to understand

I call this "bad readability" (I count how much people mention this in comments)

it's too hard to change, or it's too hard to delete

sounds reasonable