Blog 1 462

In the world of software development, writing code that is understandable and has good readability is crucial in the field. This is known as “Clean code”. Clean code allows you and other developers to understand what is being programmed and to better organize code. For example, adding comments, having variable names that make sense or that are relevant, consistency, and proper spacing so code is not overcrowded are all ways code can be considered clean.

I’m going to show a good vs bad example I’ve found online: 

In the bad example, 7 isn’t relevant and there isn’t much context. It makes you wonder what the significance of it is. Looking at a good example, you can see the 7 is replaced by a variable “Max_classes_per_student”. This is much better because it gives the 7 a purpose and is detailed. Also, the variable can be changed throughout the code if needed. 

There are many ways code can be improved to make it clean such as leaving out code in comments, overly complicated code, having too many arguments, and inconsistency. 

Overall, you should look at your code from another person’s perspective. What would you think if you were to read this code? Is it readable and can you understand it? Are there comments on complicated parts? Are your variables properly named? Etc. There are a lot of questions you can ask yourself when it comes to clean code. It is good practice to carry through your software development journey. 

Sources:

https://www.freecodecamp.org/news/clean-coding-for-beginners/

Print Friendly, PDF & Email

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *