I think I did pretty well on this refactoring :-)

It's not a direct translation of the code from imperative to functional, I had an idea along the way about making the algorithm itself simpler. But it achieves the same result.

Anyway, I just wanted to show off an impressive diff :-)

· · Web · 2 · 0 · 2

@oppen also left behind the scene: weeks of thinking about this problem :-). Something I wouldn't do on a commercial project for a company, because the code already worked well, and it would be insane to sink that much time into making things just look better. I love working on this personal project :-)

@isagalaev wow, that is really impressive diff :) the thing is that thinking non-imperatively often gives an edge about solving problems like that, that perspective when you’re not thinking about moving lower level is somehow beneficial or something

@asolovyov exactly that! Splitting a monolithic `while` doing many things at once into separate steps eventually got me thinking, "wait, why do I need this step exactly?", and then I could drop some intermediate calculations. I was completely unable to see it in the previous version, I was just happy that it worked at all :-)

Also, no matter how many times I do these things it still feels exciting every time :-)

Sign in to participate in the conversation

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!