{{announcement.body}}
{{announcement.title}}

3 Reasons Why People Write Insanely Bad Code

DZone 's Guide to

3 Reasons Why People Write Insanely Bad Code

Ever wondered why you see bad code... everywhere? There are a few reasons why this keeps happening.

· DevOps Zone ·
Free Resource

Originally published July 7, 2016

low-quality code

Now THIS is some low-quality code.

I have been contemplating over the last number of days as to why we as an industry keep producing bad code all the time.

You may also enjoy:  10 Mistakes Beginner Programmers Make

The number of developers who are able to build systems with high-quality code are few and far between, and each one is, as the cliche goes, like a needle in a haystack.

1. The Obvious Reason

The most obvious reason I could imagine is that there are good programmers and not-so-good programmers, people who are at a higher skill level and those at lower levels, those interested in the craft and the rest who don’t care about much more than the paycheck.

So, I won’t delve into that any more.

Could there be more issues at the ground level? Are there fundamental issues resulting in all the bad code? I had to dig deeper to find out.

2. Low Expectations

For one, it is widely acknowledged that the stuff learned about programming at the universities, through self-study, or books, never accurately reflects the needs of real-world jobs.

Therefore, it is always assumed that beginners are always going to learn how to produce good code on the job. It is believed that real programming lessons are only to be had with a great accumulation of experience. What's more, bad code is even expected from beginners!

When beginners are expected to produce poor quality code, more often than not, that is what you will get!

While part of the above reasoning is true, it is an assumption that I do not want to accept in full for many reasons, but mainly the three below:

  1. By expecting lower standards from those at the start of their careers, we are saying that quality is not an important factor. A direct result of low-entry barriers is having a huge influx of low-quality developers, and that leads to point number 2…
  2. By forcing them to work with mostly low-quality developers, we are making life miserable for those who do care about the craft and those who pride themselves on the quality of their work.
  3. The combination of the two factors above has resulted in the situation we are in today, wherein everyone believes they can code and professional developers are treated like commodity resources.

We need to expect more out of beginners. Who would hire a doctor if he said that he can’t perform a surgery to the highest standards, or if a pilot says that he can’t really fly an airplane without crash-landing? It's simply not acceptable. So then why is a lower quality acceptable in the software industry?

So, what is the root cause of low-quality developers?

3. Programming Books

A few days back, I was looking at some of my old books and came across a couple of books on Java – one for beginners learning Java and the other one for SCJP Certification. For reasons that will be obvious in the next minute or so, I do not want to name the books.

Unfortunately, the very books that beginners refer to inadvertently depict exactly how poor code is supposed to be.

Most beginners' books on any programming language are full of bad code. Bad code of every variety that people such as Robert Martin have covered in books like Clean Code and Pragmatic Programming are widely used in most beginner books.

Some examples of bad code you would find are…

Badly Named Classes, Variables, and Methods

i, ii, j, k for loops; clazz, SampleChapter1 for class names; etc.

No Separation of Concerns

Three-page-long main() methods that do everything instead of splitting responsibilities into different methods.

Bad Coding Practices

No good code coding practices such as including validations or exception handling. Instead, they generally use one big generic try()..catch(Exception e)  block that encompasses all the code within the class.

Another is generous use of if-else, switch, goto statements etc.

Shortcuts

The books also need to get rid of “quick fix” styles of programming. For example, it is not uncommon to find methods with 10 arguments.

Need to do two types of calculations? No problem, pass a Boolean parameter and add an if-else construct. Need to add new functionality? Got you there, add more code into the two-page long method! These are just two of the most popular.

A good way to learn programming is to master the syntax of the language, the tools needed for efficient development, and the design of components and modules that make up the code — in that order.

Unfortunately, most books stop at syntax without even briefly touching on the topics of tools and design improvements. The beginners always pick up more than what the author intended to teach. While the intent and objective of these books were to teach programming language syntax, the reader always picks up the coding style and methodology as well.

When people are learning to code, it’s important to teach them that code is written for other humans to read and understand, not just for compilers.

Hopefully, if some of you have read this post and are going to be authors in the future, please remember to have good code in the book! I myself have been guilty of using makeshift code in a number of my posts. Learning to produce good quality code should not only be confined to expert level books alone, but should be part and parcel of every book on programming!

When the beginner books contain the poorest of the poor quality code, how do we expect people who learn from them to produce good quality code?

Further Reading


10 Classic Software Development Books for Programmers

5 Pillars of Learning Programming

Topics:
good code ,bad code ,code ,quality

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}