Reviewing Clean Code

Nardiéna Althafia Pratama
HappyFresh Fleet Tracker
3 min readDec 26, 2019

In the last Clean Code post, we discussed what clean code’s about. This time, we’ll be reviewing other hackers’ codes and see whether it is clean, and if not, how to improve on it.

Source: https://medium.com/dekowarehouse-project/clean-code-mengapa-dan-bagaimana-c2be87069beb

HappyFresh

Source: HappyFresh Repository — Details.js file

This is a snippet of the Details.js file used for the front-end in SenangSegar’s application. As you can see, there is a comment in the driver_avatar attributes section — a background image was going to be inserted, but perhaps it was canceled and the hacker forgot to get rid of the commented out line of code. The rest of the front-end files seem to be pretty clean.

As for the back-end files created by one of the back-end hackers (not me), the code is already quite clean, as well, as shown in the snippet above. Not only is the file free from commented blocks of code, but there are proper variable namings — at first, it may seem that the one-letter variables go against the “proper variable naming” principle, but it is to be noted that that is the proper naming convention in the Beego framework, which is used in this project, so the principle does not really apply here.

UKM Indonesia

Now, we’ll be reviewing UKM Indonesia’s project code.

The snapshot above shows the “api-util.service.spec.ts” file from UKM Indonesia’s code repository. As shown on lines 16 and 71, there are comments which indicate that a section of the code below them are duplicates of one another, which shows how the code is not clean.

There are, however, differing methods implemented in each section. I am not too familiar with the language and framework used, so I cannot judge fully whether this kind of code duplication is a convention usually used in the language and framework, but assuming that it isn’t, then this would count as unclean code.

api-util.service.ts — Source: UKM Indonesia’s Repository

Now, in this example, the comment hasn’t been gotten rid of. This file is the most updated version in their Master’s branch, so these kinds of comments should already have been discarded. This is another example of unclean code.

Fortunately, there are also lots of files that are already implemented with clean code. This is one example below:

app-routing.module.ts — Source: UKM Indonesia’s repository

As you can see, there aren’t any unnecessary comments in the file, the names of the variables used are clear and self-explanatory, and proper annotations are also used for the method on line 16, which surely follow the rules and conventions of the framework they’re using.

That’s All!

So that is all for the clean code review. I’ve reviewed code from both SenangSegar and UKM Indonesia. They both have mainly clean code, but there are just some files that need a bit of tweaking to make sure that the code is absolutely clean.

Thanks for reading and I hope you found this post useful!

--

--