dev-resources.site
for different kinds of informations.
You have received a horrible code at work, what will you do?
This was an actual interview (which I failed) question I was asked.
The answer I said (Mostly focused on styling/structure)
Bad code might have its own purpose.
Even if the code looks messy, there might be the reason that it has been written that way. Or, at least, people are already used to it. Changing an existing schema will cause confusion and harm to productivity.
It could be waste of time to fix it.
Even though There is no reason to keep the code, fixing it might be a waste of your time, especially if when the code is not used constantly. You need to determine first if it is necessary to fix it.
The answer I have found online (focused on debugging)
Clarifying comments
figure out what the code does and try to clear it out by stating with comments for yourself and the next person rather than touch actual code to risk breaking
No risk fix
add a special case. It would be safer and faster, but the real issue wouldn't be fixed.
Delete and Rewrite
Just threw away everything and do again from scratch.
Whoever wrote this is an idiot.
It would be clean and simple.
What do you think would be the best option? Do you have another good idea? Please share your opinion.
Featured ones: