osos February 2016

Working with bad code ? do i need to refactor it?

I'm working in company with a big system with a messy code structure. I want to work with the right standards like polymorphism and design patterns.

But the code is such a mess and needs to be heavily refactored to do that. Also my current company gives me tasks, and if I have would heavily refactor, that will open many bugs in the system as it's not unit tested, of course.

What do you think? Should I work on the tasks on this bad structure to finish the work? Or tell them that we need rebuild many things (also they won't find a difference as the features already work now).

Answers


quamrana February 2016

I think you need to start off with some unit tests.

Whilst doing the tasks you have been assigned, you could write some tests to test the code you are about to change, then you can refactor it.

Now you can start to write the code for your task, test-first.

If the code that is already there works, then refactoring is the best option. If it doesn't work, then a rewrite becomes possible.


Tushar February 2016

Well...you need to work on multiple aspects.

First, learn best practices to write clean code (if you haven't yet) and request your team members the same. There are many useful books and online resources available for the same.

Second, do not expect that the situation will change overnight. Adopt "Boy scout rule" - it will gradually improve the code quality.

Third, start building your corpus of unit tests. Slowly, testable code will emerge out of the sea of untestable monolith.


Sammy February 2016

Over a period of time, if you keep building on top of this messy code, you will end up increasing the Technical Debt of your application. And I am sure at some point in near future, it will halt progress or future development on your product.

I would suggest you to use SonarQube to inspect the code quality of your application and present it to your clients. SonarQube will give you high Level statistics of your project – Lines of Code, Code Duplication, Code Complexity metrics, Unit Test Coverage, Issues in the code and the overall Technical Debt — all in one place.

Once you generate this report, you should be able to convince your clients on the need of refactoring.

Post Status

Asked in February 2016
Viewed 3,827 times
Voted 12
Answered 3 times

Search




Leave an answer