Crafting Clarity: A Journey into the World of clean code🚀
Code Needs Care!🤯

Crafting Clarity: A Journey into the World of clean code🚀 Code Needs Care!🤯

Introduction ✍🏻

Do you spend countless hours fixing bugs in your code? Have you wondered why it takes so long?

Everyone can write code that computers understand. But, not everyone can write code that humans can easily read.

As software developers, understanding how to write clean code is essential. Let’s dive into the world of Clean Code.

Table of Contents

  1. What is the clean code?
  2. What causes bad code?
  3. Why is clean code important?
  4. Comparison Between Bad Code and Clean Code.
  5. How Can We Determine if Our Code is Clean?
  6. Principles of Clean Code.
  7. Conclusion.


What is the clean code ?🤔

Writing clean code is a fundamental skill for every software engineer. Clean code is to write code that is well-organized, easy to read, understand, and maintain. Writing clean code allows others to read it without wasting time to understand it. Robert Cecil Martin made it popular. He has also gained popularity as Uncle Bob. He wrote “Clean Code: A Handbook of Agile Software Craftsmanship” in 2008.

In another sense, if three people have different experience levels, they can quickly understand the same code. It’s a clean code.

What causes bad code?

Consider this scenario: There’s a new project, and your manager gives you a tight deadline. You start coding, promising yourself to enhance it later. But you deliver the product quickly because of pressure from your manager and the customer. But, it’s poorly written. You will never return to improve it.

Oh, there is Leblanc’s law says:

“Later equals never.”

That means if you said you’d improve this later, you wouldn’t return to it.


Why is clean code important?

Let’s revisit a story from the “Clean Code” book to understand the importance of clean code. A company wanted to release a product quickly, resulting in poorly written code. When they tried to add more features, they found it almost impossible to make changes. The changes would break the existing functions and they lost all their money.

Clean code ensures that companies can add features quickly and without errors.

When we need to add more features or when someone contributes to complete with you, it will take a long time to read and understand it to fix old bugs and make new features.

When writing code implementation is simple, the difficulty is reading and debugging. That takes a long time.

Keeping code clean will give you the most value from your software. The right clean code tool can help you get there. Clean code makes debugging more efficient and unit testing easier.

A comparison between clean and badly written code.

The compiler will compile every code, clean or not. But not every code will be readable. Let’s take a look:

Can you see this?

You don’t need to understand. Let’s see first:

Bad code

Clean version

Even without understanding the code, do you see the difference? It’s formatting the code that makes the code easy to read and comfortable to the eye.

Let’s see another example. Its login page contains an image and text field.

This is the same page, but make every part a small function.

Here, we make functions with clear names. They make the code shorter. If we want to fix any part, we can go right to it.

You will never know the importance of clean code. Even though you edit your code, you will say: “What a horrible thing I wrote.”🤯

How Can We Determine if Our Code is Clean?

Writing clean code is an art and a way of thinking. It’s like a craft comes from knowledge and practice. Knowledge comes from knowing principles, patterns, and practice. So, you know this and use it in your code.

There is a Boy Scout rule that says:

“Leave the campground cleaner than you found it.”

That means we need to always check our code and enhance it. Every time we read it we will find that we can make it more cleanly.

In the book “Art of Clean Code,” they provide some questions we should ask ourselves to help us improve our code.

  • Can you consolidate files and modules to reduce interdependencies?
  • Can you divide large, complicated files into simpler ones?
  • Can you generalize code into libraries to simplify the main application?
  • Can you use existing libraries to reduce the amount of code?
  • Can you use caching to avoid recomputing results?
  • Are there more suitable algorithms for your tasks?
  • Can you remove premature optimizations that don’t improve performance?
  • Would another programming language be more suitable for your problem?

Principles of Clean Code.

Like a beautiful painting, clean code needs well-chosen colors and composition. It follows several principles. We will discuss each in later articles.

  1. Meaningful and descriptive names.
  2. Proper Indentation.
  3. Short functions that do one thing.
  4. The DRY (Don’t Repeat Yourself) Principle.
  5. Avoid code duplication.
  6. Establish code writing standards.

These principles are just a starting point; there are many more to explore and apply.

Conclusion :

“Coders spend the vast majority of their time reading old code to write new code. If the old code is easy to read, this will speed up the process considerably.”

If we write a messy code, it will reduce productivity, even if we can make it productive and enjoyable while reading it. Clean code makes it easier to reduce errors and add features without being scared to have errors in another function.

By following this, you will become a professional developer, and always remember there are no limitations to making your code clean; you can make it better every time.

That’s it! Start now and begin writing clean code! Connect with me on LinkedIn and GitHub for more articles and insights. If you have questions, contact me.

https://linktr.ee/rowan_ibrahim

Remember, “Later Equals Never.” Start writing clean code today! 😉

#cleancode #softwareengineer #writingtips

Like
Reply

اشطر بنوته 💖

Rahma Osama

Software Developer || Mobile application developer || Data analysis intern

5mo

أشطر developer و tech writer فالدنيا♥️♥️♥️

Nada Aldubaie🪄

Software Engineer | Django | Next.js| UI UX

5mo

Luv it ❤ Keep going, waiting for your next one🔥

Yousra Mohamed

Software test engineer

5mo

Very informative💗

To view or add a comment, sign in

More articles by Rowan Ibrahim

Insights from the community

Others also viewed

Explore topics