Clean Coode
I’m a student, and this past few semesters, I’ve been involved in a couple of group project, most of them requires coding. The more I code, the more I realize how important it is to write a clean code. The skit I included above kinda represent my early group projects. I once explain my entire coding session result to my team which took longer than the session itself thanks to dirty code.
So lets talk about clean code. There is many definition of a clean code, I personally can’t describe it properly, usually when I see a clean code, I’ll go “Damn, that shit good” kinda thing. The clean code practice itself is very comprehensive, so I won’t cover all the stuff. I’ll just cover the stuff that I personally regularly use or have been trying to do.
Applying clean code
Convention
Whenever I learn a new language, framework, or any coding related stuff, I always research about it’s convention. It can be naming, project structure, best practices, and many other.
For an example, I’ll elaborate more on project structure. The more framework you implement, the more libraries you use, the more complex your project structure would be. In these days, if you want to create an app or basically anything, you most likely will use a framework and a couple of libraries. Things can get out of hand pretty quickly. You can clearly see the structure difference between framework.
Each of the framework has their own project structure. Abiding the convention can help your team a lot. Angular is a component base JS framework, every component has their own folder containing the HTML, CSS, TS, and the test file. The name of the folder is the name of the component, so by just looking at the folder name, you know what the component is for. Django and Spring take a different approach since they are also a full stack framework. Both of them has a special folder for storing the frontend stuff, for Django it is the static
and template
folder while for Spring it is inside resource
folder.
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.
This CrashSqlService
class is used to map two array containing an attributes and the boolean for each of the attribute into an SQL query. Since Java and SQL use a different naming convention, I need to convert the attributes name that is using Java convention to the SQL one. Btw, I just realize that this is not the best example but please just go along with it. The process of swapping the name is done in two places, so rather than adding part of the code in both places, it is better to create a function that can be called multiple times.
But why
There are many benefits of applying clean code such as, easier test creation and consistency. Though in my opinion, the most important benefit of applying clean code is the easier development in a group environment where multiple developers working at once.
Personally, I’ve just experienced the effect of not applying clean code. In this project, UKM is actually have two projects, one is being worked on by us in this course and the other is being worked on by the intern at UKM. There is a slice where both of our project connect via an API, and sometimes I as the hacker also help with the development.
I can confidently says that our development was really dragged down because of this. The API that is already created by the other developer, in my opinion, has a really bad naming consistency. Me and fellow hacker spend too much time on understanding the schema. Communication with the developer was also really slow, which left no option other than trying to understand the schema.
Other thing that is worth mentioning is the feature isolation. It is basically that it is better to create a low coupled function. There are many benefits to it. For example, you can have a greater degree of confident when modifying part of the code, since you know what any other part of the code that will get affected. If the function is properly isolated, it is way easier to modify it. Also this will ease the test creation phase.
Now wot
Sorry that I can’t talk too much about this. Most of my clean code knowledge actually comes from regular coding. That is why when we properly learn about clean code in Advance Programming course, most of the time I was like “Is that a thing that not many people already doing?”. I also need to work on other things, so thanks for reading this small story.
clean code is what you must do in order to call yourself a professional. There is no reasonable excuse for doing anything less than your best.
Just a quote that I add from the start but don’t know where to put.