It’s a difficult and at the same time simple line to grasp. For any newbie developer, your effort is always towards writing lines of code to perform a certain specific function. As you go by, you will realize there is more than just writing codes. It’s not all about implementing a function, but making it easier for other developers to understand.
Yes, you will be employed and after a certain period, you will leave the company. How will your code be looked upon by other developers who will take over your job of maintaining it? Put yourself in the shoes of that developer. Are you able to read and make changes to what he/she has created?
Here are the questions to ask after writing your code
Can I read and explain what I have written?
May I know the working of this function I have implemented?
Am I able to make some changes whenever the product managers ask for them?
Will another developer be able to understand any of my code within a short period?
The best journey to writing clean code
Just write your code the way you want at first. Implement what you need to and make sure it’s running smoothly. All these functions need to be in order. After deploying it, and it seems to perform the duty well, at the stage of testing, revisit your code. Remove all redundant codes. They always make your application huge, which slows down your website. Look into all HTML, CSS, and JavaScript to eliminate these lines that are doing nothing.
Then on each function in your code, either java, CSS, js, or python, make comments. Let the comment define what that function is doing. Also, make sure the function titles talk more. Let’s say it’s an addition function for money. Then you can name it, addTotalMoney(). This is simple because the other developer will understand that the function is adding the total amount of money collected.
It goes to all the classes. Use noun words to stand for something. Let’s say you want to develop a school portal, so you might name the class as School().
In your code, make sure there is space from one category to another. This goes to your HTML page to ensure for every grid there is a space with a comment for another developer to understand where the image or this design is located in the code. Be precise and simple. In the backend languages also space your words. Like for example a+b=c, might be a + b = c. There is a huge difference between these two. The second one is easier to read than the first one. Remember you won’t be punished for that, but it’s good practice to space your work.
What to avoid:
Use of letters like add a +b
Too many comments on the same functions, yes it can be two to three licenses, but not more than five.
Leaving behind unused lines of code. This will slow down your loading time.
Lastly, remember another creature will work on that code as it grows. Kindly give others humble time. Let them shower words of praise upon you.
Top comments (0)