Ask HN: Codebase at my work is a complete mess, what should I do?
406 pointsAfter few days/weeks of getting to know the whole codebase I finally moved to a specific project I was suppose to work on and I found out the code is a complete mess.
Often I find parts of code that unintentionally affects other parts of code. Some parts are just copied and left there doing nothing. Even names of classes/variables are sometimes useless and project structure is unintuitive and seemingly without rules. It's spaghetti and relatively big spaghetti (tens of thousands of LOC).
I started "repairing" the project but there're no tests to check whether my adjustments are correct.
I'm so frustrated and depressed by it. The job basically turned into something I hate - I'm just rewriting the code!
The person in charge of this project was working on it alone and from the outside it all looks fine and it's working. So this makes the higher people think that it's all just fine.
I really don't know what to do.
Should I just go and basically say that this person did a bad job? I don't feel very comfortably doing that because (a) I'm a relatively new hire, (b) the person in charge is working there for about two years and (c) I'm much younger than she/he is both professionally and biologically.
I've already made some comments about rewriting it and the response was basically "ok".
Comments (333) 173 threads
Earlier commentsFirst you need to discover all associated business requirements. You need to create all the missing tests, but you cannot do that without knowledge of the business requirements. Get these requirements and get them in writing. Find them. If you cannot do this stop. Stop now.
> I'm so frustrated and depressed by it.
This is ultimately the difference between a newb, a mid, a senior, and a super duper ninjitsu rockstar.
A newb will just accept bad code and work on top of it with their own flavor of bad code. A newb doesn't know any better and everything is frustrating all the time even if the code were awesome.
A mid has just enough experience to be dangerous. Sometimes a mid suffers from Dunning-Kruger Effect in that their personal perception of the existing code isn't how they would do it and their way is soooooo superior. The mid level developers who don't suck prioritize tests and security above everything else. They know they aren't fabulous architects, but they also have some idea of where code applies known bad practices and known best practices and can work from there. A good mid isn't going to rewrite the code base, because the risk is too high. Instead they will make the most minor of best practice corrections confined to the areas they have to touch anyways.
A good senior understands concepts like automation, graceful degradation, progressive enhancement, scope, recursion, and so forth. They know how to make the code work for them. It isn't about writing a few lines of code to solve a single business requirement. It is about writing a few extra lines of code to allow the current business requirement to scale to the next thing so less work must be performed in the future and less regression occurs when the business direction shifts.
The super awesome developer takes automation to a whole new level. Documentation is automated and therefore always up to date and accurate. Debugging tools are already embedded as part of the validation process so that when validation fails you spend less time on research or resolution. Dependencies are few and well managed, because nothing pisses people off more than corruption from outside the code you own. In the end top developers value the time of other developers more than anything else and will write their code accordingly. It isn't so much about the readability of the code as it is speed of maintenance cycles moving forward.
If your job is actually important to you then you will find an acceptable level of risk that you are willing to own and have the time to practice against. Getting this right shows that you care to do the right thing without making an ass of yourself at the company's expense.
https://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
TLDR: this is hard
The biggest mistake people make (yeah, I made it too) is to quickly loose credibility with stakeholders by not providing visible value or by increasing failure rate.
Before you even start the project, you need to communicate with stakeholders and discuss what are their problems and how you are going to address them.
You also need to get very familiar with the codebase. You need to understand various patterns that are hurting it, what is their effect (are they just cosmetic problem, are they hurting reliability? maintainability?). You then need to create a step by step plan that will address those problems starting with removing the problems that are causing biggest issues, are prerequisites to resolving other issues and are least risky to deal with.
Remember, on any project like that you are spending your trust you have with the stakeholders. The more trust you have and the less expenditure rate the longer you will be able to work with.
Try to figure out how you can bring some real visible improvements at the very start of the project to build your credibility and then a string of even small successes along the line so that stakeholders are kept in positive mood.
Plan hard to avoid failures as the mood may change quickly to "why are we even doing this" when stakeholders are in hot water with their clients.
Choose KPIs and measure them throughout the project to give visible feed on your improvements to your managers.
On the technical side, it will be critical to have good development process. Automate delivery mercilessly early on -- this is key to keep failure rate in check and allow you to work at required velocity but more importantly, it is a visible improvement that you can show to your customer to build your credit of trust.
Touch the code as little as possible. Only try to fix the big problems that you have identified. If you start messing around too much you may introduce failure when fixing stuff that wasn't worth the risk and you also risk alienating other people that are working with the code base. Remember, you are making everything more difficult for them already, don't make it more difficult than necessary.
My most recent project was a mess of hundreds of components, 400k of extremely low quality code. Instead of jumping right away into fixing the code I have spent time talking to stakeholders and to what their problems were (not what I was thinking). I then quickly addressed their problems. The existing team wasn't prioritizing it highly because they didn't even know it was important... I then observed that with the existing development process I will never be able to deliver this many changes with acceptable failure rate, so I started by working on automating build, deployment and testing. Early on I identified that the high complexity of the project meant people were having hard time doing anything reliably. So I quickly prioritized reducing complexity over fixing bad architectural patterns. This helped my peers working on the code and further helped me fuel positive image of the change.
> I started "repairing" the project
Don't. Unless your immediate supervisor requests you to do the repairs. These type of efforts largely go un-noticed or un-rewarded, and only cause you stress because you care a lot about the work and the codebase. Sometimes, you even get punished for trying to do the repairs.
> I'm so frustrated and depressed by it
I know it's hard, but try not to take it to heart. There's a life outside of work, and don't neglect that at the cost of your work ethics. Have to leave you with this quote from https://workplace.stackexchange.com/a/83319/12527
> There is an incredibly rich world out there outside of work, and my sense is that all too many people get caught up in what happens within the office walls, at the expense of simply being, living in, discovering and enjoying this world. There have been some interesting survey studies of people on their death beds, and what they wish they had done more of when they were younger and healthier. Hardly anyone says "I wish I had spent more time in the office." I keep this in mind every day on my way to work, and it helps me keep my internal compass focused on the things that really matter, so that I don't regret not dedicating enough of myself to non-work-related pursuits years from now, when it may be too late.
RELATED: Try to achieve the 'Zen-like' state that the dude in office space gets into, when he get hynotized and does't snap out of it. https://www.youtube.com/watch?v=Dp7EUUVdrt0
All comments shown.
Couldn't load more comments. Check your connection and try again.