Writing "Good" Code

21 Sep 2016

What does it mean to write "good" code? When I took a course on C and C++ with Professor Ravi Narayan in Spring 2016, one of the first things he taught me was how to write "good" code. He explained that in the past, programs focused heavily on minimizing data consumption. Programmers did not have the same computing capabilities that we have today, so they had to write code that minimized the amount of data that the program would use. Every character, space, indent, and new-line was taken into account so that their programs did not exceed the data limits. The code that the programmers created was often difficult to read and understand, thus resulting in communication complications. In the past, there was a programming mentality of, "I'm going to create this super awesome and complicated program that no one can read". But in the present this is not the case anymore.


Readable Code

Narayan told us that "good" code is readable code that anyone would be able to pick it up and say: "This code looks so easy to write, I could do this". The motive for creating readable code is so that other people and programmers will be able to look at it and easily understand what you did and how. Narayan taught me his coding standard and the format that I needed to follow for every project. At first I was skeptical about coding in the new format, but I soon realized the bigger picture. The reason why the Professor had me follow his coding standards is so that he would be able to read and grade the projects easier. The same mentality translates to real world work environments because instead of professors looking at your code, your manager or boss will be examining it. And one thing that Narayan mentioned is that not all managers and bosses have programming experience. So in order to effectively explain the code, it is necessary to make it readable and understandable.

Readable Code Comic

Coding Standards

Coding standards exist so that there is less confusion in syntax and style. For most languages, a programmer will use a certain coding standard and format for each language. Choosing a particular coding standard to follow can allow programs to have consistency and look more professional.

Collaboration

When collaborating with other people on projects, it is important that every person is able to understand all code that is being contributed. It is necessary to specify the coding standard that all group members will follow to reduce the confusion when creating the source code. If everyone follows the same coding standard then it will be easier to look at another person's code and be able to understand it. The coding standard basically eliminates any style and format inconsistencies, thus making it easier for someone to look at the code and understand it.

Adapting to Different Coding Standards

It is very unlikely that all companies use the same coding standard. Therefore, it is necessary to obtain experience with alternating between different coding standards. Having experience with different coding standards makes adapting to new ones much easier. In my experience, before I started using ESLint with IntelliJ I thought to myself that it will be irritating to implement this coding standard. After forcing myself to try the new coding standard, I found that I was able to learn it by repitition. I find that I am able to learn new things by repeating the steps multiple times and creating muscle memory to adapt to it. But of course, my preferred way of learning new things is not necessarily the same as another person's. The main point here is that adapting to new coding standards is a part of Software Engineering that is unavoidable. The ability to adapt to new coding standards gives an advantage over people who cannot.