News for hackers. Stuff that matters.
Re:Why do we fall into the rewrite trap? by zaphar on Tuesday January 21, 2020 @08:57AM (#22106881)
I was around for the Google Webserver rewrite and it was actually a rewrite done by refactoring not clean slate. It's amazing what you can do with disciplined refactoring, even moving to a new language.
Re:Why do we fall into the rewrite trap? by BurningFrog on Tuesday January 21, 2020 @09:38AM (#22107239)
If you have a decent test suite to lean on, you can work miracles this way!
Re:Why do we fall into the rewrite trap? by wpietri on Tuesday January 21, 2020 @10:24AM (#22107703)
And if you don't have a decent test suite, you might as well build one. So much of a rewrite is archaeology, figuring out what elements of a system are intentional versus accidental. A great way to do that archaeology is to start weaving a net of tests around the existing system. Sort of like Fowler's Strangler Fig pattern: https://martinfowler.com/bliki/StranglerFigApplication.html
Re:Why do we fall into the rewrite trap? by majormajor on Tuesday January 21, 2020 @03:06PM (#22110934)
Yeah, if you don't have a detailed test suite, and can't build one, you probably don't fully understand your requirements, and your rewrite is in trouble already.
Re:Why do we fall into the rewrite trap? by AstralStorm on Wednesday January 22, 2020 @04:18AM (#22115916)
Mind you, maintenance is in trouble too. Just a different kind of trouble.

If you have original code, you can always write a test suite based on it, unless management is averse to this. (Begging the question why they're not averse to a rewrite.) Like any test suite it is not going to be complete.

Ultimately it's best not to get piled on by rewriting really and often in small parts. (Carmack way.)

Re:Why do we fall into the rewrite trap? by pseudoramble on Tuesday January 21, 2020 @06:04PM (#22112723)
This sounds really interesting to read about, especially refactoring into an entirely new language. Are there any articles about what that process looked like for Google at the time? Or any example that changed languages really.
Re:Why do we fall into the rewrite trap? by dpwm on Wednesday January 22, 2020 @02:11AM (#22115313)
Not the OP, and no experience with google, but I have personally worked in a way that sounds as if it could be similar:

First, you start with a slow but correct prototype in python. This can then be refactored into python closer to C, thinking about the data structures and functions that will be needed in C.

Then, you can refactor these bits into C. I've usually done this one module at a time.

You then write python bindings to this new C code. There are a number of shortcuts available here with differing tradeoffs, but you can just use the Python/C API.

In the end you're left with a C library, some bindings, and some python that just calls to the python bindings for the C library.

It would not be a huge leap to go from that to a full C implementation.

Nothing I've said here is C specific, so you can do the same with C++.

There are upsides and downsides to this whole approach. For me, one of the downsides is the amount of stuff to remember, especially some of the quirks of extending Python.

I find it easier to start with something correct but high-level in Python and work down to something easier to translate into C, even if I skip straight to the writing in C bit. I have found this usually leads to a significantly better design whilst it was still Python. You can also test the behaviour of the C and python modules against each other.