Live data from Hacker News

Let's Rewrite Everything

martinpeck.com

51–60 of 61 posts

Re: Let's Rewrite Everything

#51
A few of us inherited two code bases from a previous team, both for what are now products but were essentially prototypes.

Every release includes new things and rewritten things. If we add new on old, we grow technical debt; if we rewrite too much, fixes and features are delayed too long.

It’s a tough balance. Our code and issues are full of comments re how things should be done, with cross references we added as we figured out what things need to change together.

As Joel Spolsky notes in the twice-linked post, reading code is harder than writing.

Just today I eliminated hundreds of lines of code after writing maybe two dozen over the last few days.

The writing and deletion took no time at all. The reading and forensic mental compilation and execution took days and days.

That’s our golden rule: change nothing you do not completely understand - and you only really understand it if you can explain it in plain English to someone who doesn’t know the code.

The coolest thing is that as we go along doing cool things becomes easier and doing wicked cool things becomes possible.

Just this morning we had to force ourselves to remember that entire blocks of code with poor reporting of errors are as they are because until changes we made elsewhere just weeks ago, there was no point in doing better: the better reports had no place to go.

But after a major refactor initiated primarily to make maintenance and addition easier, we can now do things with dramatic - and wholly positive - UI/UX impacts that were simply impossible before.

Read read read read digest digest cogitate muse read read correct read confirm, explain, write.

Re: Let's Rewrite Everything

#52

Earlier quoted context omitted.

I wonder if any companies purposely avoid hiring any dedicated professional developers, and have everything done by other professionals who happen to know some code, and how it works. Developers always come with their own perverse incentive. They like the new, the clever, the smart, and the simple, and rarely appreciate the battle tested and extensible.

Having seen several projects written by people who "happen to know some code," I can tell you there's a good reason this hasn't caught on. These sort of people can work the very foundations of the company into an ungodly quagmire that would send you screaming back to the fad-chaser dev in a heartbeat. Also despite the meme, most mid-senior devs are actually keen on making their contributions valuable to the business,…

Mid senior devs do seem to be pretty good. Entry level devs who think they're senior cause most of the trouble....

I've seen some small projects by non-coders that are better than some real devs, because they can be really aggressive about avoiding original code. It might be hacky... but they find ways to leverage stuff that already exists.

Re: Let's Rewrite Everything

#53
I think this is how it should be in a more perfect world. and the purest implementation of an iterative development process.

The first implementation you write is and will always be a (throw away) prototype.

You learn a lot. You understand much more of the spec. Maybe users got a go. Maybe its just internal.

Now your write the first version. It is better. You understand even more.

Writing a proper prototype first used to be a thing. As we all know once a prototype was getting close to finished the budget changed and bam your prototype is in production.

It is not all that practical with huge applications. Perhaps there is a lesson in that.

Re: Let's Rewrite Everything

#54
post #44
post #6

This is madness. There's no real advice about rewrites in this article. The reality of rewrites is that they often fail, cost a ridiculous amount of time and effort, don't actually fix the original problem and/or bankrupt the company. You can't just wave away those realities with "think about the downsides". I have participated in a few (small) rewrites that were successful, and this would be my advice: Don't rewrite…

> The reality of rewrites is that they often fail, cost a ridiculous amount of time and effort, don't actually fix the original problem and/or bankrupt the company. Citation needed. All of these is based on random internet wisdom (e.g. Joel's condemnation, based on a different era, different delivery model, and different concerns than most of today's startup and enteprrise code), and anecdotal evidence. Well, talking…

I agree, not sure why you are down voted because you make valid points.

I can't think of any big public disastrous rewrites except for maybe frontend ones like Digg or enterprise modernizations for example when the government wanted to get rid of their 60s mainframes and the effort cost billions and was ultimately unsuccessful.

Re: Let's Rewrite Everything

#55

If the current code is crap there is a reason it ended up like that, and the same forces will be in effect to cause the rewrite to end up in the same state. Perform a root cause analysis for why the current code is in a bad state and why it doesn’t improve over time.

In my experience, rewrites are most of the time motivated by switching to the latest hyped stack than anything else.

Nobody rewrites anything in the same stack/technology.

Re: Let's Rewrite Everything

#56

Earlier quoted context omitted.

I'm convinced that bad rewrites happen because coders get bored and care more about the possibility of a little bit better code, then the whole future of the company. Necessary rewrites happen because they did too much YAGNI thinking in version 1.

For anyone else who was wondering what YAGNI is, You Ain't Gonna Need It - https://martinfowler.com/bliki/Yagni.html

There's also the concept of Pagni for the opposite:

https://simonwillison.net/2021/Jul/1/pagnis/

Re: Let's Rewrite Everything

#57
post #8

A classic Joel Spolsky post along these lines: https://www.joelonsoftware.com/2000/04/06/things-you-should-...

A classic Joel Spolsky post that completely failed to take into account the fact that Netscape rewrote itself into Mozilla, which then went on to eat IE5's lunch.

I'm a big fan (and user) of Mozilla but this take seems wrong to my memory.

Checking Wikipedia, the IE5 timeframe was them reaching their peak before stalling on the infamous IE6, and Firefox (sort of a rewrite of the rewrite) starting to make some small headway as they let IE stagnate.

https://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Br...

Re: Let's Rewrite Everything

#58
The book Working Effectively with Legacy code has some real advice for when you find yourself in this situation.

It's a lot less glamorous than just starting afresh which is where things often go wrong.

Here's a recent podcast transcript with the author looking back on the book:

https://www.infoq.com/podcasts/working-effectively-legacy-co...

Re: Let's Rewrite Everything

#59
Here's the only way you should ever rewrite something:

1) Document exactly what the existing thing does.

2) Write high-level tests for this functionality.

3) Make sure there are no features that will need to be added to it. Make sure everyone is onboard with not adding new features to it. Make sure people understand that adding features to an in-progress rewrite jeopardizes the entire thing.

4) Rewrite it in the original language, reusing those high-level tests you wrote in step 2.

5) Let people know that they can add features again.

Re: Let's Rewrite Everything

#60
post #6

This is madness. There's no real advice about rewrites in this article. The reality of rewrites is that they often fail, cost a ridiculous amount of time and effort, don't actually fix the original problem and/or bankrupt the company. You can't just wave away those realities with "think about the downsides". I have participated in a few (small) rewrites that were successful, and this would be my advice: Don't rewrite…

I just checked out "All the little things" from Sandi Metz. It's incredible! I need to get back here to say thank you for this information!
Post reply on HN