How to write Clean and Optimised Code

Introduction

Hi All, In this article I am going to write how to write a clean code and what are the procedures we follow to write a clean and optimised code.

Select a test case

Identify a test case where your code fails first. In general everyone write the code and test it but it is wrong process. First we have to identify the test case where our code fails in and then we have to notedown the expected result of the test case and check for the more failing scenarios.

Write a code

Now we have to write the code for the test case to make it pass. We have to write a simple code and check whether it is passing the test case and check for the other impacts of the code which we added. It should not break any other flow. Test it thoroughly.

Optimise and Clean the code

Now after completing the code for the test case we have to make the code more optimised and remove the unnecessary code from it. We have to make the code more clear and add the comments that give the overview of functionality of the code we added. Optmise the code for space and time complexity. Now test the code thouroghly. Once you are confident that it doesn't break any functionality then start the next step.

Execute the test cases

Run the test cases and make sure that there is no breakage of code. Now if all the test cases are passed then we can treat the test case as pass

Next step

Next step is to find a test case that breaks the code again and repeat the entire process

Thank you for reading.

Note: This article was published as my #week1 article for the Hashnode #4articles4weeks Writeathon.

Did you find this article valuable?

Support Kantimahanti Sai Prasanna Kumar by becoming a sponsor. Any amount is appreciated!