Skip to content

Why should we do Clean Code in programming?

Last updated on December 17, 2023

If you were a coder, I think you should have heard about the keyword “Clean Code”, right? However, I believe there are not many people who truly understand about CleanCode. So that, why should we make “Clear Code” in programming? For its answer, let’s take a deeper investigation from this article.

Oh, I forgot! In this blog, I only focus on the reasons why should we make a CleanCode, I will not show you HOW we do that. If you want to know more about this, please refer to this article: 12 Conventions for Writing Clean Code

Quick view

What is “Clean Code”?

Before answering WHY we must understand what is the definition of clean code because once we understand the definition so we will understand why it is important.

CleanCode literally understands at making your code is clean and tidy. In detail, CleanCode includes:

  • How the structure of source code.
  • How to scientifically implement source code.
  • How to make the source code easy to read and understand.
  • How to do best performance for the application.

Applying CleanCode to your project is a piece of cake, but doing it correctly is a different aspect.

Clean Code helps easy maintaining.

Maintainance is a very very important part of programming as well as application development. There is no application that could run smoothly year by year without maintenance. So if we write a good and tidy source code at the beginning, maintained guys will be easier to understand the source code and make quick fixes.

When the project starts, applying clean code will help all the structure of source code and every single script clean. Your team members will follow the coding conventions and the structure to continue developing whole the project. Down the road, the project will be simple for whoever involves in it.

Clean Code lets other programmers easier understand your code.

As I mentioned above, there would be many members in a project working together. Each member will have a different style of coding. For example:

// Style 1
public function doSomething() {
   // Other coding
}

// Style 2
public function doSomething()
{
   // Other coding
}

I have been suffered so many pains when I was reading messy code like this:

foreach($arr_salesorder as $k=>$v){ 
  if(isset($arr_task_by_so[(string)$v['_id']])){
  $v = array_merge($v, $arr_task_by_so[(string)$v['_id']]);
}
  $v['payment_due_date_int'] = strtotime($v['payment_due_date']->toDateTime()->format(DATE_RSS));
  $v['payment_due_date_str'] = date("Y-d-m", $v['payment_due_date_int']);
  if($v['payment_due_date_int'] < $nowdate)
    $v['late'] = 1;
  else
    $v['late'] = 0;
  $arr_asset_data[] = $v;
}

See? You just rolled your eyes when seeing this messy code. I did not mean to make it messy, I copied it from one of my real projects. If you are an understanding clean code programmer, you will write an understanding code for other people to read.

Clean Code shows your professionalism in programming.

Why does writing CleanCode show your professionalism in programming?

Have you ever done interviews or joined interviews? You will see the employers assess the level of a programmer due to many criteria. However, if programmers understand clean code, they will show their technical skills and expertise in some way.

Showing a beautiful code will help to impress interviewers. In every interview, we could do some coding challenges to show our technical skills. Some people will ignore formatting and indent your code when doing code challange, it is a mistake. The interviewers will have bad consideration to the messy code even your logical solution was perfect. So, pay attention to writing stunning code!

Clean Code creates a common rules.

The rule is the first compulsory thing of a company or a team would like to become professional. To the software companies, it will be more reasonable, especially is in the developed department. Sometimes, the rule makes annoys developers that they could not have creative thinking, but it helps all programmers quickly adapt to the projects.

On another hand, a ruleless team (at a small company or inexperienced in development company) would usually make bugs and fatal errors on their products. Their software will be unstable and source code quality is extremely bad.

In fact, making a clean code rule is very difficult, we should have a strong understanding clean code members (usually are tech leaders) will bend all members into stunning shapes.

Conclusion.

Yeah, that’s it. So now I believe you had some knowledge about CleanCode definition. It will be more detailed in the real project but at least now you had a mindset that writing beautiful code is important.

CleanCode is also an important skill for a programmer, if you would like to learn more about this, I recommend you to read 2 books

  1. CleanCode: A Handbook of Agile Software Craftsmanship
  2. The Clean Coder: A Code of Conduct for Professional Programmers.

Cheers.

Published in⌨️ Programming TipsBlogs

Comments are closed.