6 ms·
"Conventional wisdom holds that you should never rewrite your code from scratch, and that’s good advice." Speaking as someone who has done a fair number of rew
by mcguire 7y ago
"Conventional wisdom holds that you should never rewrite your code from scratch, and that’s good advice."
Speaking as someone who has done a fair number of rewrites as well as watching rewrites fail, conventional wisdom is somewhat wrong.
1. Do a rewrite. Don't try to add features, just replace the existing functionality. Avoid a moving target.
2. Rewrite the same project. Don't redesign the database schema at the same time you are rewriting. Try to keep the friction down to a manageable level.
3. Incremental rewrites are best. Pick part of the project, rewrite and release that, then get feedback while you work on rewriting the next chunk.
- tptacek 7y ago#3 is in fact what they did, and what this post is mostly about, though their releases were apparently internal.
- leeoniya 7y ago> Don't redesign the database schema at the same time you are rewriting. 100%. rewriting all layers simultaneously is the first step to never finishing.
- taeric 7y agoI internalize this as every rewrite is a race to feature parity. Keep your races small and be prepared to call them off and devote energy elsewhere.
- razemio 7y agoThank you! I read the first sentence and had to speak "bullshit" out loud. Sometimes rewriting something feels so good. Especially after some time has past and you are still in the process of learning. You apply all the things you have learned and your are amazed how much better it has become.
- tptacek 7y agoRewriting things always "feels so good", which is why people offer up the advice not to do it.
- hello_moto 7y agoDepends on the size of the re-write. If it's small, no problem. If it's big, it's a death-march for result-driven developer => because at the end of the re-write, the product is still more or less the same, just different engine. Some developers prefer to leave the company during the re-write (which usually happens after 3 years exciting hyper-growth).
- kjeetgill 7y ago+1 on all fronts. Rewrites/big refactors can be tremendously helpful 3-4 years in a big project's life. At least on the stuff I've worked on, that's around the time that accumulated tech debt has built up and the problem domain the we were hoping to solve is now well understood with production traffic.
- jt2190 7y agoPoint 3 seems to redefine “rewrite” as “partial rewrite”, which is essentially in the spirit of “never rewrite the [whole] code[base] from scratch”. Am I missing something? Edit: Clarified quote of original rule.
- mcguire 7y agoTake a typical CRUD app. It'll have, say, something for inserting data, editing data, viewing data, and reporting. Pick one of those chunks (reporting is good; it's usually easy and gives insight into the data) and rewrite that. Release it (if it's a web application, modify the old app to redirect reporting requests to the new app). Lather, rinse, repeat until you have a completely rewritten app. It is more along the line of "don't try to do a big-bang release of everything" when you are initially writing an app.
- nwienert 7y agoThat’s exactly what they are doing, it says it in the article.
- m463 7y ago"refactor"
- chinhodado 7y agoThere's this classic article on the topic: https://www.joelonsoftware.com/2000/04/06/things-you-should-never-do-part-i/ https://www.joelonsoftware.com/2000/04/06/things-you-should-...
- atesti 7y agoIronically, FogBugz will be rewritten now: https://www.fogbugz.com/blog/fogbugz-rebuild-spec/ https://www.fogbugz.com/blog/fogbugz-rebuild-spec/
- mattl 7y agoFogBugz went from being ASP to ASP/PHP (Wasabi) to some version of .NET where they hosted it all. I can’t believe FogBugz didn’t share any code with CityDesk.
- dfabulich 7y agoJoel's article is the famous classic, but he proved himself wrong when his company, Fog Creek, built Trello from the ground up, sharing no code with FogBugz. Trello became a huge success while FogBugz languished. https://medium.com/@herbcaudill/lessons-from-6-software-rewrite-stories-635e4c8f7c22 https://medium.com/@herbcaudill/lessons-from-6-software-rewr... (I think this article should be the new classic.) > My takeaway from these stories is this: Once you’ve learned enough that there’s a certain distance between the current version of your product and the best version of that product you can imagine, then the right approach is not to replace your software with a new version, but to build something new next to it — without throwing away what you have.
- gknoy 7y agoWow. This article you linked seems worthy of its own HN submission. Thanks for sharing it!
- statictype 7y agoNot a great example, I think. Trello isn’t a rewrite of FogBugz. It’s a brand new product.
- paxys 7y agoYour third point is arguing against the premise. A "partial rewrite" isn't a rewrite. That's the entire point.
- deleted 7y ago[deleted]
- kbenson 7y agoAt some point a partial rewrite might become a complete rewrite. It depends. Ship of Theseus[1], etc. 1: https://en.wikipedia.org/wiki/Ship_of_Theseus https://en.wikipedia.org/wiki/Ship_of_Theseus
- mattmanser 7y agoBut that's not what Joel was arguing against when he first wrote the article against rewrites.
- paxys 7y agoLiterally referenced in the article
- m463 7y agoThe easy way to fund a new military plane is: - remove one bolt and raise in the air - slide out rev 30 "parts" from beneath bolt - slide in rev 40 "upgrade parts" (fuselage, wings, engines, etc) underneath the bolt - fly "upgraded plane" without a lot of pesky 'new plane" studies Additionally, in parts of california, how to build a house: - find existing house - pick a wall - remodel everything except for that wall - reap tax benefits in your 99.9% new house.
- deleted 7y ago[deleted]
- bin0 7y agoThat's sometimes a good strategy, but breaks when you do too much at once. See boeing's recent fiasco where they did basically just that with parts and a fuselage that weren't really compatible. Metaphor extends: try to replace too much in part and something will break.
- ergothus 7y agoIncremental rewrites (aka refactoring) is best, but sometimes that's just not viable, which is where I feel conventional wisdom breaks down. If your code is trying to get updated, you can usually refactor. If your code is having a paradigm shift, it's likely any incremental rewrite will take more time and have more duplication without benefit for far too long to be successful.
- s_y_n_t_a_x 7y agoIncremental rewrites !== refactoring. You can rewrite portions of the app and embed the older components in the new app until you rewrite them as well.
- dragonwriter 7y ago> Incremental rewrites (aka refactoring) Refactoring is recoding a component while maintaining it's external interface so that external interactions with the component are unaffected. Rewrites, incremental or otherwise, do not necessary preserve external interfaces (an incremental rewrite doesn't start clean slate, but instead progresses by gradual replacement of existing code. The two ideas are not closely connected.
- wvenable 7y ago> Don't redesign the database schema at the same time you are rewriting. Chances are, that's the problem though. You have to re-write because your design is bad enough that it's necessary. The only time you'd re-write without changing the design is when changing languages or platforms.
- coldtea 7y agoYou could do a rewrite that takes into account the bad old database schema, but doesn't repeat the wrong code design choices based on it. Then, when that's ready and stable and working with the existing schema, it's way easier to do a refactor and adapt to the new schema too.
- wvenable 7y ago"Show me your flowcharts and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won’t usually need your flowcharts; they’ll be obvious. " -- Fred Brooks, The Mythical Man-Month Attempting a design re-write without changing the data structures will just result in the same design. And you can't change the data design without then having to change the code to match.
- dougk16 7y agoI've done several huge rewrites over my sordid career, and a strategy that works well is to abstract your bad data design behind a good one. This involves some kind of transformer layer between your bad data design spec and your abstracted better one. There's of course performance hits of some kind no matter what, but the hope is that they're worth the benefits of the cleaner code/architecture that the better data design spec affords. It's difficult I'll grant, much harder than abstracting simply bad code, but it's possible, and also makes it that much easier to replace the actual data design at some point in the future, and remove the transformer layer. Hope that makes sense!
- wvenable 7y ago
- mattbillenstein 7y agoRe #2 - sometimes the code isn't all the problem, but it is the schema - and the two can be intertwined in such a way that you can't fix one without fixing the other.
- Ididntdothis 7y ago3) is usually the only way to go if something has a little bit of history and complexity. It’s almost impossible to capture all features and uses of a system completely and then deliver something that does all of these things. Much better to work in small increments which can be understood. It may take longer and feel less heroic but at least you always have something that works.
- deleted 7y ago[deleted]
- dragonwriter 7y ago> Incremental rewrites are best That's perfectly compatible with the conventional wisdom you claims wrong, which, again, was “you should never rewrite your code from scratch” [emphasis added]
- zepolen 7y agoJesus NO at no.2 Rewrites are ALL about the schema. Look, over time, your initial requirements will change. The initial schema will 100% not be what is ideal. On a long enough time scale EVERYTHING becomes many to many. I've found any rewrite of software without restructuring the schema has always been a waste of time.
- abraae 7y agoYep, I've never seen a system that was a) so bad that it requires rewriting and b) had a great schema that rewrite could be done on top of. Usually a quick glance at the schema will shine a bright light on top of all sorts of badness - denormalizations, excessive metadata-driven-ness etc. Rewriting code on top of crud like that would be epensive, and result in a lot of ugly code, which would need to be rewritten again.
- zepolen 7y agoRight, rewrites are basically invest now vs spend exponentially later. They make little sense as soon as a project is completed, even if you rewrite, the software hasn't had time to point you in a direction, a 'nice' rewrite of the same wrong solution is just as useless as a bad implementation of the wrong solution. They may make sense after a product has matured, since the actual scope of the software will be more defined. The 'correct' schema is starting to reveal itself, but usually it's rare that business wise it's worth rewriting at this stage, adding features is the better choice. They definitely make sense once a product is fully matured, starting to gather legacy issues - since fighting around all the cruft and incorrect schema restrictions is wasting more time than redesigning it from ground up using the existing implementation as the guide.
- flukus 7y ago#1 and #2 ignore why a rewrite is happening in the first place. No one rewrites a system for fun, they're rewritten because the current codebase has major failings that prevent new features or make the current codebase unworkable. These should be the first things added to a rewrite to prove that it's not a wasted effort.
- PopeDotNinja 7y ago4. If the version X team is writing version X + 1, that knowledge is gonna help a whole lot.
- mikekchar 7y agoThe reason to avoid rewrites is because they generally get cancelled, or they build the wrong thing. In the first case, you have a system that mostly does what you want, but it has architectural issues that make it hard to change. You plan a rewrite. You get buy in from management. But the problem is that the business still needs those changes. If your rewrite takes more than a few months, then you're still going to have to do the changes. Over time, you end up with 2 groups: legacy and greenfield. The legacy group is usually made up of crufty old salts that don't care what they work on. They just grind it out. The greenfield group contains usually younger people who what to do something new. They want to "get it right" this time. They care deeply about what they work on and so there is usually a fair amount of conflict on the team about how to approach just about anything. The legacy team grinds along, slowly solving business problems and the greenfield team provides no business value until they are finished (while constantly promising that it will all be amazing as soon as they are done). But the business types see only that the legacy product is doing what they want and that the team is quietly plugging away. The greenfield product does not do what they want and the team seems to be doing a lot of excited talking, but it still isn't finished yet. So they say, "Wouldn't it be better to move the greenfield team back on the legacy product so that we can get things done faster? After all, they said they couldn't move forward with the old architecture, but it's moving forward just fine. And with more resources it will go along a lot faster. Besides we have these business emergencies that we have to deal with, so let's just put the greenfield project on hold for a while until we can sort out exactly what's best". And the greenfield project is effectively buried. Now, it doesn't have to turn out this way, but powerful forces point you in that direction and you have to be very careful not to have it happen to you. The other main problem is that when people think about doing a rewrite the requirements document usually looks like "Do exactly the same thing as the last system". But the problem is nobody actually knows what the last system does precisely while simultaneously they all think they know precisely how the old system works. You get a lot of push back from the business when you start gathering requirements because the only thing they really want to say is "Just do it like the old system". Only, after months and months of development you end up realising that there were a lot of corner cases that you missed in the rewrite. Oh... and it's not possible in the new architecture to do that without jumping through a lot of hoops. So, incremental rewrites are best, but only if you can get the business to actually use the greenfield project. Normally they will completely ignore it because their paycheque and their promotion and their happiness depends on being able to do their job at least as well as they could with the old system. And the new system doesn't do everything that it needs to do (because we've released incrementally). What's more the developers keep asking stupid questions like "What do you want it to do" and the business people are responding with "Why can't you listen to me? I've told you one hundred times to do it the same as the old system!" And so the new system is shunned by the business. It becomes radio active. Unless some upper management type sends a mandate down to force the business to use the new system, nobody will touch it. The upper management, in the meantime are wondering, "Why are we doing a rewrite again? The old system seems to do what we want, while everyone is complaining about the old system". Yep, it can be done, but it requires considerably amount of help from upper management. You should avoid it at all costs unless you are sure upper management is supporting you all the way. But even when you are successful, it may just be the beginning of the end. You've managed to stave off cancellation. You've managed to keep user engagement and work through the requirements so that the new system is equivalent. But it turns out that there is some small detail or decision that makes the new product non-viable. For examples of products I've been personally involved with: Word Perfect 5 was written in assembly code and was not based on Windows. Word Perfect 6 was rewritten in C++ and was based on Windows. The team that did the rewrite were very proud of their work. But they through out all the keybindings in WP 5 (because GUI is way better!). The new rewrite was also very, very slow compared to WP 5. This was the beginning of the end for WP, even though one could definitely say that a rewrite was necessary. They just made the wrong choices. Similarly, I once worked for Nortel and they had a telephone switch that they sold for $10 million a pop. It had 31 million lines of code (and stinky, stinky, stinky code at that). They realised that they could rewrite it in a fraction of that amount of code. They had 3000 developers working on the rewrite and after a few years they succeeded. Only... it didn't work with all of the business equipment that the old switch worked on. And it turned out that nobody wanted it unless it worked with that equipment. And.. the new architecture was not conducive to making it work with the business equipment. In the end, they gave a few switches to China before they abandoned it. Rewrites are hard even when you've made the right choice to do it.