Live data from Hacker News

Ask HN: Codebase at my work is a complete mess, what should I do?

news.ycombinator.com

81–90 of 346 posts

Re: Ask HN: Codebase at my work is a complete mess, what should I do?

#81
Every programmer that has ever existed has said and felt this exact thing. It used to really bother me as well. Then I realized that the world is a messy place and I would need a stronger stomach if I was going to watch the sausage being made. Don't refactor because it violates your delicate sensibilities about code - that's a great way to waste a lot of money and get yourself fired.

Greenfield development or maintaining a legacy code base that isn't complete shit is a luxury. Leave things better than you found them but you have to earn respect/influence before you can start attempting sweeping changes.

PS - https://blog.codinghorror.com/the-ten-commandments-of-egoles...

Re: Ask HN: Codebase at my work is a complete mess, what should I do?

#82

1. Stop "repairing" it because you're guaranteed to introduce bugs and regressions. You haven't learned it well enough and can already sense the fragility, which is why you're anxious. 2. Relate your impressions to the person in charge: "The code doesn't seem to follow best practice and appears fragile. You think there may be technical debt that needs to be addressed sooner than later." 3. Until you're confident enou…

> Some people are comfortable working around fragile and wonky code Yep, because I have worked with very bad codebases over the past 25 years, I actually enjoy the challenge. For me it is more rewarding than working with pristine and well managed code bases.

Ditto.

I was explaining greenfield vs. brownfield to a co-worker (non-developer) between periods of fixing a previous, junior, developers code that was essentially creating a seemingly infinite number of pages on our site.

Keeping in mind the above, I also know that deadlines, changing requirements, and lack of a clear goal (due to the previously mentioned items), lead to this. Had I not worked with them, my decade and a half of experience would have strongly suggested that such was the case.

When it comes down to it, some people prefer working on new projects, and some people prefer supporting and polishing those once-new projects. But to really succeed you've got to be able to do both, to some extent.

Re: Ask HN: Codebase at my work is a complete mess, what should I do?

#83

Is it buggy? Is it insecure? Is it slow? If the answers to those questions are no. Then you the problem and you should look for employment elsewhere. You are unhappy in that job, and you rewriting the codebase would potentially make the above questions answer to a YES, inflicting damages in the company. Now, if the above questions have yes as an answer. Talk to your manager, explain how it won't scale, how it is hack…

This seems like a great post to vent a little bit. I'm definitely a bit touchy on this subject. I like to think I'm pretty good at programming, development, and generally architecting solutions. I don't have a lot of experience, but I have a bit of talent and spent a lot of free time learning. Solving problems with computers is something I'm passionate about. I started this particular project without any idea of what…

I feel like this is how most legacy code bases are made.

> Never giving me a chance to justify it, or even reading the commit messages, to understand why it was done that way.

This is a surefire way to re-introduce bugs that were fixed ages ago. Understanding why things are the way they are is the first order of business when working within a legacy code base. Was it done this way because the obvious way has a non-obvious edge case? Was it a requirement from the users? Or was it just the fastest way to do it at the time?

You have to have a certain mindset to effectively work on legacy code, and this isn't it. Most more junior developers I've known have a "rewrite" oriented mindset, meaning they don't know how to work within the constraints of what exists and refactor piecemeal. It's a hard to learn skill, generally learnt the hard way.

Re: Ask HN: Codebase at my work is a complete mess, what should I do?

#84

I moved mostly to real estate after running an IT company for 15 years. You know what they say in this field about 19th century buildings, which are certainly technically inferior to newly constructed houses? „At least these buildings have been standing for a century without collapsing“. IOW, the code you are seeing is at least in production, while many other companies did things differently (perhaps in a prettier or…

>Sorry if this isn‘t helping, but have some respect for a codebase that seems to be working. And write lots of tests before touching it.

This right here is the best advice I've seen in the thread. Lot's of people are giving good advice here.

Definately write lots of tests before touching it. As you write the tests you may even start to see a pattern or "method to the madness".

Re: Ask HN: Codebase at my work is a complete mess, what should I do?

#85
post #3

Are you working at my company? Ok, more seriously: that’s the way existing code is about 90% of the time - it’s the reality of working in our field. It may or may not reflect on the original developer. Maybe they were learning a new framework. Maybe they were rushed. Maybe it was originally intended as a prototype but ended up in production. Maybe the requirements have grown or changed significantly since it was impl…

This is good advice, especially on the communication part.

It's always tempting to use the word "rewrite" but most of the time you just want some assurance that your code doesn't break things, and a rewrite is usually overkill.

I would suggest you to add in additional time for refactoring into your new feature development. This has 2 benefits - you're not rewriting the whole project, just the parts that are relevant to what you are currently working on, and you're still pushing out features.

It sounds like most of your refactoring work is in code isolation / scope management and creating tests.

Re: Ask HN: Codebase at my work is a complete mess, what should I do?

#86
post #66

Earlier quoted context omitted.

This seems like a great post to vent a little bit. I'm definitely a bit touchy on this subject. I like to think I'm pretty good at programming, development, and generally architecting solutions. I don't have a lot of experience, but I have a bit of talent and spent a lot of free time learning. Solving problems with computers is something I'm passionate about. I started this particular project without any idea of what…

> reading the commit messages, to understand why it was done that way. that's assuming the original authors used version control, committed often enough to leave meaningful commit messages, and bothered to explain their decisions. pretty much every code base i've taken over in my current role have consisted of a single posting commit with zero documentation.

Given the context, I think the individual that you're quoting said that because they did do that within the commit messages.

And outside of the one place where I was the person to introduce source control to the organization, I've found commit messages to be pretty telling. Most developers tend to let their feelings pop out in their commit messages, and too when and how often they're committing.

In your particular case, sounds like either a junior developer, legacy systems, or a sole developer.

Re: Ask HN: Codebase at my work is a complete mess, what should I do?

#87
Don't fix things just for the sake of fixing them. Let new features, bugs, or necessary performance improvements drive your changes. Keep your changes small and focused. You need to ensure that you're delivering business value with each change, rather than embarking on an overwhelming, open-ended task.

This is critical if you want the business to support your effort. It demonstrates pragmatism. It will shrink the scope of your changes and make the problem less daunting. You can prove to your boss and your coworkers that it's possible to fix the problem without slowing down new development efforts.

Be careful how you express your dissatisfaction with the code. Many of the people who wrote it are likely still there. Approach every change from a positive angle, so you don't alienate your peers. Get them to help you make the changes, and help them to learn how to become better developers. Don't assume they don't know better; they may have inherited a mess too, and they may have been under pressure to deliver quickly at any cost--or maybe they just don't know any better, but want to improve.

Read these books:

_Working Effectively with Legacy Code_ by Michael Feathers

_Refactoring: Improving the Design of Existing Code_ by Martin Fowler

_Clean Code_ by Uncle Bob

These are invaluable resources. There are many others, but these three are particularly germane to your situation.

Re: Ask HN: Codebase at my work is a complete mess, what should I do?

#88
Start deleting the shit code. On Fridays I went on a rampage and ended up deleting 50k lines of code. I spent some downtime and just randomly updated some really old dependcies. Then find particular areas that can be isolated but keep it small, and include reliable testing data.

Don't be afraid to pragmatically say "this code is dogshit". But don't ever expect a full or even a large rewrite. But you can move the bar forward one piece at a time.

If you have the flexibility, just go do it. As the phrase goes, better to ask for forgiveness than permission.

Re: Ask HN: Codebase at my work is a complete mess, what should I do?

#89
What you describe is called technical debt. https://en.wikipedia.org/wiki/Technical_debt

A strategy of unethical developers is to make themselves relevant by producing a lot of features while drowning the project in technical debt.

This often happens when:

a) stakeholders are not technical.

b) their strategy is to have an early exit (like an acquisition) before the problems caused by the technical debt materialize.

c) they can compensate for the technical debt hiring an army of thousands of developers.

I would say it is a management problem. And like all management problems, unless you can fix that, your best option would be to spend your peak productive years in a company that cares.

If you want to take issues to management, tread very lightly. First of all, your challenge will be to present the problem while not seeming depressed, irritated or pessimistic, or heavily criticizing others. Try to sell the idea using a positive twist, like increased productivity, robustness, etc. If that doesn't work, just start interviewing.

---

If you decide to stay, just start creating tickets from all the technical debt. Make sure to include details like commit links, and objective information about how it is a problem. Then:

- link bug tickets to tech debt tickets.

- link incident tickets to tech debt tickets.

- if a task requires a tech debt workaround, create a separate ticket for the workaround and link it to the tech debt ticket.

This should create some sense of visibility around the tech debt. It will likely won't work anyways:

- Some people feel smarter and empowered when they deprioritize tasks.

- The only ability of uncreative managers is to say no. Saying no makes them feel useful.

Post reply on HN