Clean Code

Rizal Alfaridzi
UKM Heroes
Published in
3 min readNov 1, 2019

How do you apply Clean Code?

Well, since i am learning a new framework (Angular) it means it has different kind of “clean” so let’s get jump to our project and see what you can know about clean code! .

Project structure

when it comes to the structure of your project it depends on how many frameworks and libraries you use. And separating modules is always a must when it comes to clean code , because it will maintaining our reusability and will still organized

landing-page module and event-page module

in our project structure , we could see that there are 2 things that are , event-page and landing-page which are separated from each other but still put on the same directory which is pages.

DRY

DRY is an abbreviation for Don’t Repeat Yourself. It is basically telling programmer that if some part of the code will get repeated, that part of the code needs to be dealt with. In this instance, I use the practice of “extract method” where basically I extracted some part of the code to become a standalone function.

from the abbreviation it self you already know that we can not repeat our code, meaning that we need to reduce code duplication.

api-util.service.ts

in our project, we could see in our api-util.service.ts , there are no repetition of our code so it will maintaining the use of our function. well you can still use the function just by calling out their names rather than duplicate in different place.

Consistency

when it comes to naming convention and stuff, consistency is a must so it will not make my fellow programmers confused to understand whether the structure or the code itself.

naming convention in our project structure

so from the picture above what can you see?. is it hard for you programmers to understand ? ,no? well it because we apply our consistency in naming our modules by changing our whitespace into “-” so it will easier for us to find what modules that we need to do.

Comments

The only truly good comment is the comment you found a way not to write.

  • Don’t Use a Comment When You Can Use a well named Function or a Variable
  • Any comment which forces you to look into another module for meaning has failed miserably in communicating and is not worth it at all.
  • Don’t comment bad code, Rewrite it. — Brian W. Kernighan and P. J. Plaugher

in our project, we not really use comments cause i am pretty confident that our code can be readable with out giving comments ;)))

Now what?

well you now have read this, what are you going to do now? well yes. You also need clean code because, since our project not only containing one member. Means that our code can be easily understand by other fellow programmers (Andre, Ilman , and friends). other than that, it makes me easier for testing our features in our project (since because the naming convention and the layout of project structure implementing clean code).

okay, so that’s all i can tell you about clean code because i need to get back on working our project. i would love to tell you more after i find any interesting things while i am developing this project. Bye!

--

--