News for hackers. Stuff that matters.
Re:LibreOffice: cleaning and re-factoring a giant code-base ... by tomelders on Sunday February 17, 2013 @07:12AM (#5235001)
I was talking to a friend about "legacy code" the other day and I realised: the company that's going to put you out of business won't have any legacy code.

I think you need to have a really good excuse not to completely rebuild your product from scratch every now and again. Because if you don't, someone else will.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by bryanlarsen on Sunday February 17, 2013 @07:40AM (#5235046)
OTOH, the greatest asset you have competing against the company that's going to put you out of business is your legacy code.

Every line in your legacy code is there for a reason. Sometimes the reasons are bad, but often they're there because of some very valuable lesson you learned from a customer, a mistake you made that your competitor is also likely to eventually make. Throwing away your legacy code means that it's likely you'll make the same mistake again.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by cpressey on Sunday February 17, 2013 @07:47AM (#5235063)
Legacy code will also tend to have had many of its bugs ironed out, since it's been in operation for so long. New code will have a whole new set of coding errors hidden in it, and you'll have to go through that ironing-out all over again.
Re:LibreOffice: cleaning and re-factoring a giant code-base ... by dhimes on Sunday February 17, 2013 @08:11AM (#5235093)
I think this is a crucial point we all overlook in our rush to throw out the legacy code and 'do it right this time.' We're thinking, 'but we'll have unit tests so we'll catch the bugs.' But in reality, some get through and they tend to be a real pain in the ass.

I know this probably means that I don't unit test right. It also obviously means I don't code right, because I have bugs. The point is, these are facts of (real) life, and to be successful you have to manage the reality. Often this means that the best course of action is to stick with the legacy code.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by tomelders on Sunday February 17, 2013 @09:15AM (#5235242)
You'll have bugs either way. That's a fact of life, and the vast majority of a developers time will always be spent debugging.

What legacy code does is inhibit your ability to make the fundamental changes you need to implement in order to stay competitive. And I'm not saying throw you code out every other week. And I'm not saying every attempt to rewrite your product should replace what you already have. But the for all the costs associated with re-writing your product, they pale into insignificance when compared to being put out of business.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by dhimes on Sunday February 17, 2013 @10:04AM (#5235383)
In terms of debugging, there are certainly the goofs (off-by-one, = instead of ==, and so on) which are just lapses by the programmer. The danger I think is in losing the wisdom gained in having already solved the hard problem (of course it is helpful in this regard if the original programmers are still around somewhere). It's something akin to cultural knowledge. Don't underestimate what it's going to take to rebuild it.

But perhaps we can agree, then: rewriting code is a business decision, driven by the business needs of the company. Premature rewriting is just another form of premature optimization, and can get you in trouble by putting your resources in the wrong places. But when you have a tangible threat- when you are unable to adapt to accommodate needs that you are convinced are on your horizon, then you should do it.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by cpressey on Sunday February 17, 2013 @09:51AM (#5235350)
It should go without saying that fewer bugs is better than more bugs, though.

I'm not saying you should never rewrite a system from scratch. But I do think it's extremely costly to do so, and that it's extremely difficult to predict when you'll be driven out of business if you don't. So I don't think it's usually justifiable.

I'd be very interested if someone could supply an example of a company that was put out of business because they failed to re-write their product.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by Tyr42 on Sunday February 17, 2013 @10:49AM (#5235512)
If you already saw a threat, then by the time you finish re-writing it, wouldn't you be dead?
Re:LibreOffice: cleaning and re-factoring a giant code-base ... by dhimes on Sunday February 17, 2013 @12:50PM (#5235990)
Depends how well you can see the threat horizon.
Re:LibreOffice: cleaning and re-factoring a giant code-base ... by nathan_long on Monday February 18, 2013 @08:29AM (#5238088)
>> What legacy code does is inhibit your ability to make the fundamental changes you need to implement in order to stay competitive.

There's always the possibility that your existing code doesn't suck, and was designed to be flexible for changes.

Ideally, you've done a good job and can rewrite small pieces of your system iteratively as needed, rather than having to chuck the whole thing.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by berkut on Sunday February 17, 2013 @10:50AM (#5235513)
Exactly.

Also, code that might look crap and seem to do weird stuff often handles intricate edge cases. But due to the lack of comments, it's not obvious what's going on.

I've been involved in several component refactorings when as a team we've gone "look how complicated the old code is, we can make it much simpler".

When we've re-written it and then tested it with actual production use cases, it then becomes obvious why the code was so convoluted previously. So time was wasted, but at least there are comments now (and in those cases, the code's slightly better).

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by tomelders on Sunday February 17, 2013 @09:02AM (#5235203)
It seems there's an assumption here that building your product again means throwing out all of your experience. What I thought would have been self evident is that by starting again, you bring to the table all your experience and you harness that to build a better product.

Because that's exactly what someone else is going to do. The company that makes the product that competes with yours is unlikely to have picked your product at random and simply decided to compete against it on a whim. There's a good chance they've been using your product and have become so frustrated with it's shortcomings that they've had a crack a building there own version. They've been on your support forums that detail every bug and bad descision, they've read the blog post detailing exactly what is wrong with your features and how they could be done better. They've stared at their screen in a full on rage wondering why the hell your product doesn't do things in a way that makes sense. They have their own experience and they are not afraid to use it.

There could be one, tens or hundreds of people who decide to do this. Many will fail, but if one succeeds then you have a serious problem. The continued success of your product can no longer rely on it's features unless you're prepared to make some fundamental changes. Only now you have a deadline, whereas before you could have worked at your own pace.

You're right when you say your legacy code is your greatest asset. It's proof of what is a good idea and what is a bad idea. But that doesn't mean you should keep it around any longer than you have to.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by JohnBooty on Sunday February 17, 2013 @12:50PM (#5235987)
"It seems there's an assumption here that building your product again means throwing out all of your experience. What I thought would have been self evident is that by starting again, you bring to the table all your experience and you harness that to build a better product"

Ideally, yes! Realistically, there's always some hairy, gnarly wisdom "baked into" the code.

The definitive article is Joel Sposky's article on the perils of writing from scratch. If you only want to read a few paragraphs:

"Back to that two page function. Yes, I know, it's just a simple function to display a window, but it has grown little hairs and stuff on it and nobody knows why. Well, I'll tell you why: those are bug fixes. One of them fixes that bug that Nancy had when she tried to install the thing on a computer that didn't have Internet Explorer. Another one fixes that bug that occurs in low memory conditions. Another one fixes that bug that occurred when the file is on a floppy disk and the user yanks out the disk in the middle. That LoadLibrary call is ugly but it makes the code work on old versions of Windows 95.

Each of these bugs took weeks of real-world usage before they were found. The programmer might have spent a couple of days reproducing the bug in the lab and fixing it. If it's like a lot of bugs, the fix might be one line of code, or it might even be a couple of characters, but a lot of work and time went into those two characters.

When you throw away code and start from scratch, you are throwing away all that knowledge. All those collected bug fixes. Years of programming work."

http://www.joelonsoftware.com/articles/fog0000000069.html

Ideally, yeah, you take that wisdom with you to the new project but realistically (even if you've followed great documentation practices, etc, for all of those hairy kludges) the rewrite-from-scratch is never as easy as one thinks.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by peteretep on Sunday February 17, 2013 @08:12AM (#5235094)
> the company that's going to put you out of business won't have any legacy code

Code becomes legacy pretty quickly, in my experience... Architectural decisions that were obvious before you had real customers rarely stand up to real usage.

The company that's "going to put you out of business" also doesn't currently have any working or revenue-generating code, and are unlikely to immediately understand the architectural challenges...

> I think you need to have a really good excuse not to completely rebuild your product from scratch every now and again

It pretty much just doesn't work in the real world; how's that for an excuse? As other people have said, you need to scaffold interfaces, and rebuild small parts. Any company that isn't continually reinvesting in making their codebase better will accumulate technical debt pretty fast; but the throw it away and start from scratch approach rarely works on big systems.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by tomelders on Sunday February 17, 2013 @08:32AM (#5235129)
Maybe, maybe not. I've never been presented with any evidence that supports that view. I'm not saying you're wrong, I'm just saying I've got no reason to believe you're right. And vice versa.
Re:LibreOffice: cleaning and re-factoring a giant code-base ... by jodrellblank on Sunday February 17, 2013 @08:46AM (#5235166)
http://www.joelonsoftware.com/articles/fog0000000069.html

It is just someone else saying the same thing, or it's a real world example, or it's anecdotes-aren't-data.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by bijupunalor on Sunday February 17, 2013 @08:56AM (#5235188)
"Netscape wasn't the first company to make this mistake. Borland made the same mistake when they bought Arago and tried to make it into dBase for Windows, a doomed project that took so long that Microsoft Access ate their lunch, then they made it again in rewriting Quattro Pro from scratch and astonishing people with how few features it had. Microsoft almost made the same mistake, trying to rewrite Word for Windows from scratch in a doomed project called Pyramid which was shut down, thrown away, and swept under the rug"

"Things You Should Never Do" http://www.joelonsoftware.com/articles/fog0000000069.html

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by yuhong on Sunday February 17, 2013 @08:05PM (#5237535)
Not exactly the same mistake but this is even worse: http://yuhongbao.blogspot.ca/2012/12/about-ms-os2-20-fiasco-...
Re:LibreOffice: cleaning and re-factoring a giant code-base ... by jacques_chester on Sunday February 17, 2013 @07:21AM (#5235017)
> I think you need to have a really good excuse not to completely rebuild your product from scratch every now and again.

And I suppose we should also burn down factories and rebuild them every now and then.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by Drakim on Sunday February 17, 2013 @07:29AM (#5235025)
If the factories are operating with giant iron cog wheels older than your grandmother, then maybe yes, we should.

The world of software is moving a lot faster than the physical world, so things can become outdated pretty quickly. Compare a 15 year old browser to a 15 year old factory.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by jacques_chester on Sunday February 17, 2013 @07:55AM (#5235076)
I think that wasting money on solved problems is, essentially, bonkers.

Sure, it's nice to have the latest and greatest. But I don't think it gives you magical powers. You still need to do all the other stuff.

That, and the well-known problems with rewriting (the track record is notso hotso) mean that really, the onus for making a case to rewrite is on the rewriters.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by mauvehaus on Sunday February 17, 2013 @10:24AM (#5235436)
The difference between a browser and a factory that makes say, steel wheels for cars, is that while the web has changed dramatically in 15 years, the basic requirements for a steel wheel have not. As long as your machinery can hold the required tolerances and make product profitably and while complying with the laws that apply (like environmental), it would be foolish to scrap the old factory.

If the market starts shifting to alloy wheels, and the reduced volume of sales for your steel wheels starts to affect the profitability of your factory, then maybe it makes sense to start looking at investing in updating your process to make steel wheels more cheaply at lower volume or to dump steel wheels entirely and start manufacturing alloys.

The Air Force Heavy Press Program made the rounds on the internet last year when Alcoa refurbished its 50,000 ton forging press in Cleveland [1]. It's been around since 1955, and it's almost unique in its capabilities within the USA. The idea that it should be replaced simply because it's old is, frankly, insane.

That's obviously a pretty extreme example, but the fundamental requirements for a metal lathe or end mill haven't changed in years. Yes, there are multi-axis CNC machines that can do vastly more operations before somebody has to change the setup on them than on a basic lathe or mill. If you aren't making something that requires a lot of steps, the basic lathe or mill might still viable.

Just because the rate of change in requirements over time is huge in software doesn't mean that it's true everywhere. If an old factory can continue to meet the requirements, it's probably hard to justify changing it just to be up to date.

EDIT: Forgot the link

[1] http://www.theatlantic.com/magazine/archive/2012/03/iron-gia... [1]

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by cpressey on Sunday February 17, 2013 @07:44AM (#5235052)
This attitude strikes me as wasteful. By all means, if a system has shortcomings, and you can afford to build a new system with fewer shortcomings, and migrate to it, then do that; but by itself, "it's old" is not a reason to rewrite something.
Re:LibreOffice: cleaning and re-factoring a giant code-base ... by jackalope on Sunday February 17, 2013 @08:34AM (#5235135)
I think I'd rephrase that to:

The company that's going to put you out of business is using an early version of their own legacy code.

It's not always obvious when you should attempt a rewrite from scratch. Having done a few refactorings, I've noticed one desirable trait in good code bases: If you can implement new logic easily in a few lines of code, it's probably a good design. But if you need to get out the surgeon's knife and write tons of new code every time you want to implement new logic, it might be fundamentally flawed enough to warrant a complete rewrite. A good design is adaptable and will allow you to be resilient against newcomers.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by abbyroad9191 on Sunday February 17, 2013 @08:55AM (#5235186)
If it ain't broke don't fix it. If you've got a team of about 10 - 15 engineers that'd be over a million dollars you'd be burning in 1 year for a code rewrite. And most code rewrites that I've seen or been a part of take more than 1 year.
Re:LibreOffice: cleaning and re-factoring a giant code-base ... by greenyoda on Sunday February 17, 2013 @09:26PM (#5237812)
I'd agree with the "more than 1 year" estimate for any large code base. It could even be several years if your run into unforeseen problems. You probably don't want to even start a rewrite like that without first spending a few months thinking really hard about the architecture of the new system and making sure you'll end up with a feature set that does everything that your customers depended on in the old code.

And furthermore, while the developers are rewriting the code, who is going to maintain the old code? The demands for new features and bug fixes aren't going to stop just because you've decided to rewrite the code.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by coldtea on Sunday February 17, 2013 @09:02AM (#5235204)
Netscape was put out of business for doing just that: rebuilding Mozilla/Geeko from scratch and missing lots of time while MS grabbed market share.

Sure, we know have Firefox, but that's little consolation for the corporate entity that was Netscape.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by nathan_long on Monday February 18, 2013 @08:26AM (#5238070)
>> the company that's going to put you out of business won't have any legacy code.

Even assuming their newly-minted code is better (which others have disputed), what they don't have is loyal customers and brand recognition. If you're worth competing with, you do.

>> I think you need to have a really good excuse not to completely rebuild your product from scratch every now and again.

There could be many reasons. 1) That's expensive. 2) May introduce new bugs. 3) Interface changes may alienate existing customers. 4) Switching technologies may require new developers.

I wouldn't say "plan to rebuild from scratch periodically." I'd say "design your software to be flexible, watch your competitors, and iterate to ensure they don't leave you in the dust." If it becomes clear that you can't compete on features without a rewrite, then consider it.

Re:LibreOffice: cleaning and re-factoring a giant code-base ... by Surio on Sunday February 17, 2013 @09:15AM (#5235241)
Re:LibreOffice: cleaning and re-factoring a giant code-base ... by sultezdukes on Sunday February 17, 2013 @08:35AM (#5235139)
I consider "legacy" code any code that has been committed and is dependent upon. I look at code that is 3 weeks old (has had a few additional commits), and start cringing. All code gets ugly fast. At the end of the day you have to pick your battles wisely.