How do you convince your manager that your project needs huge refactoring?

I joined the rails project as a contractor. The project will last more than a year. The code is written by about 10 different developers, and most of them are also contractors. They have a different code style. Some of them appeared in Java. The code has terrible grades with metric_fu. Many functions are very long (100 - 300 lines). Some functions have an insane amount of logical branches, loops, and recursions. Each query generates a ton of sql queries. Performance is very poor. Many outdated codes that were never used, but never got the opportunity to be cleared. The core architecture is simple or complex. Code coverage is only about 25%. The views and partial things are chaotic and terrible to read and understand.

The manager is in a position to try to satisfy the CEO, constantly adding new features, however, it is becoming increasingly difficult to implement new functions correctly without breaking something else. He knows that the code is bad, but does not want to put too much effort into fixing it, because refactoring will take too long.

As a contractor / developer, what is a good way to eliminate this situation and the convenience of the manager or CEO to split the time for refactoring?

Matters Related

How to convince skeptical management and colleagues to allow refactoring of horrible code?

How to reorganize the budget

Work with illogical managers

+6
ruby ruby-on-rails refactoring
source share
10 answers

In my limited experience:

  • It is impossible to convince the manager that you need to allocate time for refactoring. You can tell him about it and strengthen the point every time you encounter a problem due to bad code. Then just move on. I hope your boss finds out.

  • It is quite common to get into a running project and think that "this is complete junk." Give him some time. You can begin to see a pattern of insanity.

+16
source share

I was in a similar situation. There are only two options:

  • You get some relaxed time, and you can be given time to refactor.
  • Due to poor code, further development of a component comes to a stall. You cannot continue to add anything because every small change causes everything else to stop functioning. In this case, you will get "go" with refactoring.

I just answered in another question, my horror story:

https://stackoverflow.com/questions/1333077/dirty-coding-tricks-to-deliver-project-on-time/1333095#1333095

I worked on a project where the basic principles of development were dirty tricks. Needles say that after some time, these tricks began to conflict with each other. In one analytical component, we had to implement another very dirty trick - to hide those calculated values ​​that, due to conflicting tricks, were not calculated properly. Subsequently, tricks of the second level began to conflict, and we had to create tricks to cope with them. Since then, even mentioning this component makes me feel terrified that I may have to work on it again.

This is exactly the second situation when refactoring is the only way out.

In general, many managers who do not have a technical base (in fact, those who come from poor programmers) do not care and do not understand the value of high-quality code and good architecture. You cannot force them to listen until something interrupts their plans, like hitting “impossible” functions, increasing and repeating errors, requests from customers who cannot be satisfied, and so on. Only then can an understanding of code problems arise for the first time. Usually it's too late.

+2
source share

Everything is missing here:

Refactoring is part of the software development life cycle.

it is not only a RoR or any specific project, but any other software development project.

If you can somehow convince your PM why it is important to reorganize the existing code base before adding any new function, you should clearly indicate to your PM that any addition of a new function without any refactoring will take more time than required. And even if a function is added, one way or another, error resolution sessions will take even more time, since the code is very bloated and not processable.

I really don't understand why people forget the optimization principle later. Optimization later also includes refactoring later IMHO.

One more thing, when you make design decisions, you have to be very clear about your consequences, good or bad, for your PM.

You can create another branch (I assume you are using git) to refactor and start adding a new function to some other branch if your PM insists on adding a new function along with refactoring.

+2
source share

Refactoring that sucks is part of the coding, so you don’t have to approve anyone if your manager doesn’t keep track of your code and watch VERY closely. . The time that I keep refactoring today is the time that I don’t need to do the count, doing crazy tricks to get the normal code to work tomorrow (and it will, in the end).

Interrupting methods into smaller methods and removing methods that are not used are part of your job. Reducing database calls in the code you call is also necessary so that your code does not suck. Again, not really refactoring, just normal coding.

The conviction of your manager depends on other factors, including (but not limited to) their willingness to be convinced and your ability to convince.

In any case, what is massive refactoring in RoR? Even if "the underlying architecture is simply wrong," it can usually be aligned a little at a time. Make sure you break it into pieces / use branches so as not to break anything while you are busy committing.

If this is not possible, return to the social question of how to convince your manager. This is a simple question - to find out what he has, and to push them, they did not fire and were not arrested. Hiding, hiding food, giving prizes, being a friend, anonymous abductions when you enter and save the day ... It's pretty simple, in fact: creativity is the key!

+2
source share

Difficult, I recently worked for such a company ... they always pushed for new things, again they knew that it was bad, but no matter how hard I tried, I even brought in external consultants to check my conclusions - they saw it as a waste of time .

In the end, they saw the light ... it took him just a few server crashes, and at some point after almost 8 days there was no website to convince them.

Even so, they insisted that it should be a hosting service.

The key is to try to determine the amount of time that their site will be idle before it crunches, and get some external verification to support you - "they always trust outsiders who don't know anything about your application! Also, try - if possible, give a plan that involves a gradual replacement in the worst case, and a plan of how long it will take, and also a plan if 1 or 2 bodies are working on a complete rewrite of hwo, which may be required, but be realistic or it will If you take this route (this is what we did), you can still work on an existing site if you include it in a new one.

+1
source share

I would advise you to focus on things that they can see for themselves, that is, they will definitely notice that the application is slow in some functions, so take one of them and say something like “I can reduce the waiting time here, I can spend some time to improve this particular thing? " (more well said, but you got the point: P).

Also think that 10 developers, before you reorganize the code base, this may mean that this is a monstruos task, most likely will make the situation worse, in this situation, if something goes wrong after refactoring, it will be your mistake if the program no longer works. Simple, though, but worth considering.

+1
source share

I will take one small piece of the application and reorganize it and optimize it until it shines (and I will do it in my personal time so as not to annoy my manager). Then you can show your manager / CEO the good results of refactoring and optimizing SQL.

0
source share

If there is a need for a refactor, then the code will speak for itself. Minor refactoring may continue during development. If you cannot convince the manager, then you should probably reconsider, if necessary at all.

However, if this is absolutely necessary, the construction of development performance indicators and benefits should convince the manager.

0
source share

I think one option would be to tell the manager how redistributing the code base will now save time (i.e. money) in the long run. If the project will work for a long time, then making changes at this time will clearly save you and other developers in the future.

It’s best to use the example function you were working on to estimate how long it would take if you had cleaner code to work in the first place. Good luck

0
source share

Now I am in the same position, but with the agreement with the manager that when a new function needs to be implemented in some existing module in order to re-fix the module (if it needs to be re-factorized), we are now struggling with the code created 4-5 years ago, and I definitely learn that re-factoring someone else’s code is not trivial or fun, but very useful for future reuse.

0
source share

All Articles