Live data from Hacker News

Ask HN: Started a new job and their existing code sucks. What to do?

news.ycombinator.com

11–20 of 66 posts

Re: Ask HN: Started a new job and their existing code sucks. What to do?

#11
Be a little more relaxed about this. Legacy code often looks like a big elephant which needs lots of fixes. Look to the tiny things instead:

- just make the function / class you're working on nicer, preferably just a small function. Apply some common quality standards to it, clean code, nice docs. - repeat this for a while, and you will have a nice set of examples and guidance for the other team members by setting an example.

Personally I am a huge fan of making that one place where you found the bug nice, adding a simple test case and moving on to the next thing. It adds up over time and does not hurt in terms of time involvement/budget since you already had to invest a larger amount fo time to find the place bugging out.

Re: Ask HN: Started a new job and their existing code sucks. What to do?

#12

Be a little more relaxed about this. Legacy code often looks like a big elephant which needs lots of fixes. Look to the tiny things instead: - just make the function / class you're working on nicer, preferably just a small function. Apply some common quality standards to it, clean code, nice docs. - repeat this for a while, and you will have a nice set of examples and guidance for the other team members by setting an…

"Be a little more relaxed about this" is probably the best advice haha. I think I just freaked out when I saw their code/had to debug it. But, as @pascalxus said, this is probably very common in many places.

Re: Ask HN: Started a new job and their existing code sucks. What to do?

#16
Maybe you've been lucky so far working with good code.

Most code is like this, it's semi-painful to work in. Once you have been working on it a while you'll be more used to it.

I would spin it more like this. Hey if we refactor/rewrite this we can improve it and knock out these bugs in the process.

It may be hard to convince the company to spend money on refactoring let alone writing tests. But you can always ask in a positive way to start on parts of it.

You get paid the same, be positive, fix bugs/issues, improve things where you can. Keep making positive suggestions.

As a developer you're almost always going to feel the urge to rewrite every app from scratch. I expect the code is making them money and they just want to keep things moving for now.

At some point there is usually a rewrite from scratch, maybe that can be your project.

Good luck with your new gig.

Re: Ask HN: Started a new job and their existing code sucks. What to do?

#17
I find the Boy Scout Rule to be helpful:

> The Boy Scouts have a rule: "Always leave the campground cleaner than you found it." If you find a mess on the ground, you clean it up regardless of who might have made the mess. You intentionally improve the environment for the next group of campers. Actually the original form of that rule, written by Robert Stephenson Smyth Baden-Powell, the father of scouting, was "Try and leave this world a little better than you found it."

> What if we followed a similar rule in our code: "Always check a module in cleaner than when you checked it out." No matter who the original author was, what if we always made some effort, no matter how small, to improve the module. What would be the result?

http://programmer.97things.oreilly.com/wiki/index.php/The_Bo...

Apply it as you go. Piece by piece. Perhaps encourage your fellow developers to adopt the practice.

Re: Ask HN: Started a new job and their existing code sucks. What to do?

#18
There is no one magic bullet to deal with such a problem. Instead there are several things you can do in parallel to help. Whichever of these works for you depends on the industry and age of the company you are in.

If the company is fairly new, then bad code is kind of expected. There is a rush to get a product out the door, so shortcuts are taken. Given time for things to settle v2 will be better.

If its an established company or the code is legacy you can fix little bits as you go along. If documentation is lacking, write some - maybe even set up a wiki and bug tracking system if need be. If comments are lacking add some.

If you can demonstrate the bad code is costing the company more in man hours (and therefore money), then maybe propose a a series of refactoring projects in order to help improve the code and increase efficiency. I worked at a company that would have refactoring parties once a month with pizza and chipper. On the last Friday afternoon of the month we would review 10 random code files changed in the last month and tidy messy code, add comments, docs, unit test etc.

Suggest the company adopt some coding standards if they already haven't. Ditto code reviews and unit testing.

Of course not all companies are receptive to such changes. Some take the view that if the product works, why wasted time on frivolous extra like docs and code reviews. Sometimes when the code has been primarily the work of one person they might not take kindly to criticism - even if valid. In those cases all you can do is just do is to write your own code as best you can and not worry about what goes on around you. Bad code is a lot more common than you expect and life is easier when you accept that.

Re: Ask HN: Started a new job and their existing code sucks. What to do?

#19
Consider the fact that you just joined the company, and are likely unaware of many complexities, dependencies, and edge cases that the code must account for. I suggest working with the code a bit longer before you make such bold proclamations as to its quality.

Also consider your teammates built that code. How do you think they felt when you told them it needs a whole refactoring? Since you cannot refactor it in secret, you would need to get your manager’s approval to take on such a project. He is going to ask your teammates, who built the code and whom he’s known longer than you, for their opinions. So it’s important to have their support in refactoring.

It seems like a needless risk. You have a low chance of success (first, convincing your manager, and second, successfully refactoring the code), but a high chance of loss (alienating your teammates).

Re: Ask HN: Started a new job and their existing code sucks. What to do?

#20

Be a little more relaxed about this. Legacy code often looks like a big elephant which needs lots of fixes. Look to the tiny things instead: - just make the function / class you're working on nicer, preferably just a small function. Apply some common quality standards to it, clean code, nice docs. - repeat this for a while, and you will have a nice set of examples and guidance for the other team members by setting an…

If there’s literally no structure in place for running tests, then OP cannot just add “a simple test case.” OP also needs to build the test runner. That requires convincing his manager, who is likely the one responsible for this mess (by claiming maintainable code is not a priority).

Personally I think it’s irresponsible to hire new employees before having a maintainable project. It’s much easier to onboard employees and delegate to them when they have a safe dev environment and testable projects to break while they learn.

Post reply on HN