top of page
  • Abdul

How To Write a Clean Code

#prints hello world

print(“Hello World”)

You might be wondering why I wrote print("Hello World"), so in case you are unclear as to what it means, it is a line of Python code that prints Hello World on terminals. If you are unfamiliar with coding, you can use this method. in LEARNING

You are all doing programming, which maybe divided into two categories: programming and good programming. Most of you have written your own programme as well, so if I asked you to work on my code and change it so that I could get the desired result, you'd probably say, "Sure, I can do that." It would be difficult for you to grasp if you opened my code and saw lengthy functions described on a single line without any further information in the comment lines. The significance of clean code is now brought up, and the cleaner your code is, the better programmer you become.

You all might be thinking right about now that if I add a comment, I'll automatically become a good programmer, but that isn't the case. Yes, adding comments makes the code easier to manage, but there are also many other factors that can make your code look cleaner and more maintainable. Let's take a closer look at these factors.

● What should be our top issues while writing clean code?

● Coding is similar to cycling on a road.

Out of all the ideas we implemented from Clean Code and other sources, five provided at least 80% of the gains in productivity and team happiness.

1."It's broken unless it's tested."

So, when you develop code, you should test it. You maybe wondering why this is necessary, but if you don't test it, you will likely have a problem. So, write plenty of tests, especially unit tests, or you will be sorry.

2. Select names that are meaningful.

You may have heard that when creating variables, classes, or dictionaries, you should give them meaningful names. Why is it that everyone says that if you're not excellent at naming things in your code, it'll turn into an unmaintainable nightmare? That implies the other developers or team members won't understand how your code works, and if someone wants to maintain your code, it will be tough for them to do so.

3. Classes and functions should be kept to a minimum.

What does "little" mean in terms of functions? There should be no more than four lines of code. You read that properly, four lines. It appears fairly random and tiny, and you've probably never developed code that is little and produces the desired effect.

4-line functions, on the other hand, push you to think hard and choose a lot of friendly names for sub-functions, which makes your code self-documenting and more maintainable. Furthermore, they imply that you cannot utilize nested IF statements, which compel you to perform mental acrobatics in order to grasp all of the code paths, and this is how you should think while developing a function.

4. The consequences of functions shouldn't be negative.

Side effects are actually terrible and make it incredibly difficult to write code that is free of problems such as infinite loops, incorrect variable names, and so on. It happens when you don't execute or test your code, which is why the first point is so important: "If it isn't tested, it's broken." It is common for functions to enter into infinite loops; this is a side effect of a function.


You all know what is comments, yeah I am talking about programming comments, not the instant comment shah I got you. So back to the topic, we use comments to explain the functionality of the line or the functions or the variable etc. It helps the coders to understand the code more easily.

To summarize, remember and practice the following four "clean code" concepts to enhance your code productivity drastically:

1. "It's broken if it hasn't been tried."

2. Select meaningful names

3. Classes and functions should be kept to a minimum.

4. There should be no side effects from the functions.


I hope I have given you a basic explanation of how to write clean code and what things you should keep in mind while creating code. You are all programmers, and you should begin implementing these functions in your code to make it more attractive and manageable.

•••••••••••••••••••••••••••••••••••••••••• Facebook : Instagram : LinkedIn :

4 views0 comments

Recent Posts

See All


bottom of page