What Makes Code Bad?

If you can’t identify bad code, you can’t possibly fix it

@yungnoma unsplash.com

Imagine this: You’ve been procrastinating working on one part of the project. After postponing for a week, today is the day that you plan to venture into that legacy codebase and take a look at what’s been done. The thought of it scares you. You know that the offshore team has touched this code over the years. You know that the code is about five years old. You know that you were brought in to make improvements. Rather than scrapping the whole thing, management decided to “reuse” the code due to budget issues. Now, you are in a foreign country. You hope that what’s waiting for you on the other side is “Good Code.” But, you know that there’s a 95% chance it’s simply “Bad Code.”

You start your day with a giant mug of coffee to make the process less painful. Within a few minutes, you come in contact with a specimen of code that is just awful.

Spaghetti Code — by Jun Wu

Not only does it resemble the drawing that your three-year-old just made, but some of it also resembles your three-year-old’s favorite food.

By identifying exactly how bad the code is, you can potentially re-argue your point to management that it’ll take twice as long to fix than to rewrite it.

Unreachable Code

This is a code that will never be reached unless the logic is changed.

For example:

function {} {

return x;

z=a+b;

}

The fix: Remove it.