Creating Clean, Clear, Comprehensible Code

20 Sep 2023

A few days ago, a friend of mine who was an exchange student from the mainland came to for help on one of his coding assignments for an intermediate level Java course. He was by no means a novice when it came to programming; he had experience in Python from his first few college semesters on the mainland. However, due to credit transferring issues, he needed to take most of his intro-level courses again. Regarding the assignment he requested help with, I managed to help point out a few errors that were due to him misreading his instructions. Finding the errors themselves was all fine and dandy; it was a trivial matter. However, what was not trivial was the sheer amount of effort I needed to put into simply comprehending his code.

I can sympathize with my friend for procrastinating on and rushing through his coding assignments for this introductory course. The assignments he was forced to do were designed and created for essentially beginners in coding. For an intermediate-level student like him, these homeworks must have been mind-numbingly boring and likely nearly unbearable to power through since they were large projects due at the end of each week. This is why I am not even mad that he ended up completely forgoing his coding style and standards. I am not mad about his sloppily placed his brackets, one-letter variable names, or seemingly random indentation. I am, however, mad that I had to read and attempt to understand that atrocity.

Code for others, not yourself

It may vary depending on the context, but at least in software development, the code you write will likely be read not only by yourself, but by others who may be working on the same project as you. In the case of an open source project, there may be exponentially more people reading your code. For this reason, having coding standards is crucial to writing good, effective code that can be reused by other programmers. To accomplish this, it is imperative that your code is written clearly and consistently. Consistency is the key here- just because the code you write is correct, doesn’t mean that other people can read it if you follow a certain convention in one place and then completely ignore it in the other. Would YOU want to read code like that?

Regardless of who you are writing code for, it is still good practice to at least try to format your code correctly as you are writing it. Unless you are a genius who can write flawless code right off the bat each time, chances are you will find some bug or need to change something in your code. When this inevitably happens, who are you going to blame if you struggle to comprehend the code you wrote previously because you didn’t follow any standards at all?