If the code works don’t fix it

In this blog, we focus quite a bit on helping beginners and increasing their knowledge. The sentence “if the code works, don’t fix it” is sometimes taken as a rule by newbie developers. Though most of the times it works, i Personally think it is just an excuse from lazy developers.
In this post we’ll explain why and when should you actually fix the code.
Why Should You Fix it ?
There are a lot of benefits from fixing your code :
- Becomes more readable by other developers
- Improve the code quality
- Improve the code performance
- having testable code
- having extensible code
There are more opinions you can see , check here
When You Shouldn’t Fix The Code ?
Let’s get this out of the way and talk where this “rule” should be applied.
- you are new to a job and still haven’t figured out the architecture and the project structure but they order you to fix something that already works.
- if you think you’ll introduce problems to the existing code.
- do you understand that piece of code ?.
When Should You Fix it?
It Depends on many Factors :
- Is The Code Complex ? : When it comes to complex code it depends on your experience. can you clean up the code and make it simpler ? if yes then you should change the code. using either design patterns or clean code architecture.
- What Are The Gains ? : It always comes down to the results. Will the software gain performance ? does it help when adding new features ? does it improve readability or flexibility? scalability?
- How Long Will it take ? : Is the time that you are going to spend fixing this code equivalent to the amount of gain you get ?
How To Fix?
Following These Steps will help you fix the code :
- read the code until you understand it and comment the parts where it’s incomprehensible.
- Separate logic from state management.
- Break the logic down to pure functions that are easily testable.
- Add unit tests to ensure that you can change the code without breaking it
3 Responses
[…] Try to solve it on your own : having a problem doesn’t mean you don’t have a solution. so try your best with the help of your previous experiences. […]
[…] is a repost with little modifications of a post originally in my blog. zairiaimen.com If you don’t want to read the post, you can also watch the video version of it […]
[…] is a repost with little modifications of a post originally in my blog. zairiaimen.com If you don’t want to read the post, you can also watch the video version of it […]