DEV Community

loading...

Discussion on: How do you cope with bad code?

Collapse
gsto profile image
Glenn Stovall

The code we read is not the code that was written.

Someone probably didn't decide to write the code you are working on now. It's probably years of modifications of people making the best decision they could with the context and information they had at the time. So I remember that everyone did the best they could with what they are given, just like I am now.

Secondly, I make whatever improvements I can along the way. Even if its leaving comments to help me understand what is going on. Refactoring in small bites can help you move faster, so the argument about having a deadline is moot.

Thirdly, maybe it doesn't matter. If the code works and is providing business value, then code in kind and ship it. Everyone will happier with a working pile of spaghetti over a nicely manicured and late submission.

Collapse
sudiukil profile image
Quentin Sonrel Author

Thanks for the reply.

I'd usually agree with what you say but here the code isn't "bad" because it's the result of years (it's a few months old) of modifications... but because it was done by someone who isn't a developer. So yeah, it's just bad code. And to be clear I'm not blaming anyone, all things considered the code runs well, but it is absolutely unmaintainable, which is my main issue with it... because I do have to maintain and extend it.

Also sorry but no, my argument about having a deadline isn't "moot". The client basically gave me a week to do something they weren't able to do in over a month... so respecting the deadline is almost impossible even by barely doing the minimum, let alone refactoring any part of the code.

I don't know, maybe I'm at fault here, maybe I should be able to work with such a code, and it's not the first time I have to work with legacy code, but in this case I really can't get anything of it.