Refactoring like a Marxist

If your old code has problems, delete it and rewrite everything

André Gillfrost
6 min readNov 6, 2020

A long-lived code base is like a society.

It’s a living thing. Sometimes well kept, often not. People will come and go. Those who went all had good intentions …until reality caught up!

Sometimes you will come across an area that doesn’t work well. You’ll dive in to find out why. After countless hours of trying to figure out what’s going on, you’ll ask yourself; who the **** would solve this problem this way?

Next, you’ll have a very strong intuition about how to fix this mess:

Tear it all down and rebuild it correctly, from the ground up

Yes, go with it. It’s the right thing to do. The system is so damn rotten there is just no way to fix it. Smash it into atoms, and build a better one.

Some of your colleagues will agree. Some won’t, and claim that

“refactoring is a very specific technique, founded on using small behavior-preserving transformations” -Martin Fowler

Pfft! The behavior IS the problem. If they can’t see the that, they’re part of the problem. Of course they want to keep the current system. It’s what’s feeding them the power to exert such an extreme amount of dominance over you, without even noticing! It’s disgusting, how much power some individuals have. We’ll handle them later. Back to rebuilding.

This time it will be nothing short of perfect! The way to go about it is certainly not to delegate the decision making. How can you build a perfect system if you don’t know what’s being built, right? This time a large amount of power is allright, because it’s in the right hands. It is used for good.

Architecture

Have you heard about the Ivory Tower? Apparently, it’s where all the best software architects hang out. And boy, does it sound like the perfect place to centrally plan your new system! From there you can see exactly what’s going on, and make sure everything is proceeding according to plan. Now you have the moral high ground, and the physical.

It’s time to decide the perfect architecture, one that will work for every part of your system. Maybe you know about the Don’t Repeat Yourself principle? To hell with that! In the perfect system, every part is just like every other part. That’s how you make it maintainable. Not rocket science. With that sorted, let’s get into the specifics.

Rename

Names may seem like petty details, but don’t be fooled! Names hold tremendous power. Take the term ‘Dependency Injection’. That is obviously pretty offensive to heroinists. Or at least it could be. Or at least I think it could be, so it is. That term must be replaced, to stop the discrimination against heroinists. You see now, how dangerous words are. If something is so sorely needed as to be an injected dependency, why not call it ‘Supportive Handoffering’, to take away some of those negative connotations. You need to change all these words and terms into something more comfortable. Like taking off that horrible office attire, and slipping into your PJs, all soft and inoffensive.

Types

Let’s call them for what they are: stereotypes. Remember that. If you’re using a statically typed language, your first move will be to abolish it. If it’s static, it can hardly be the start of a revolution!

Who are you to decide what type something is beforehand? A boolean is just a social construct. Besides, who in his right mind would dream up the silly idea that something can be represented with only 2 states? That’s binary, for crying out loud. Binary means bigoted, and his name is George Boole. Yes, Google his complexion, age and sex, and you’ll see he’s up to no good.

So what’s the solution? The Rainbool, of course. It can be true, false, tralse, flue or anything, really. Or nothing. Let that code be what it wants to be, when it wants to be!

Object-Oriented Programming

Can you see how that is just another way of saying Capitalist-Aligned Schooling? Yes, programming people to be obsessed with things. Does that sound like a good thing? America tried, and they’re not exactly in the avant-garde when it comes to computer software. Trash that stuff.

The cure is called procedural programming. That‘s fancy for ‘everybody understands’, or ‘put one foot in front of the other programming’. It’s a march to victory!

Testing

But wait a minute. Before you tear everything down, you have to decide whether you think it would be a good idea to write some tests. See what works and what doesn’t, currently. Maybe that could be a good guide when building the new system?

Wrong! You don’t need a test to tell you everything is rotten. You already know that, so don’t waste time. It all has to go because, well, it just all has to go. At this point, some self-proclaimed rationalist comrades will try to act experienced, and suggest Test-Driven Development. Slap them. You want Dogma-Driven Development.

Classes

Ah, classes, the heart of the matter. There’s a lot to say, but we’ll stick to refactoring. Remember what we said about binary and bigotism. There is one domain where that doesn’t apply; the nature of all things. Everything around you can be divided into one of two things, good or bad. Everyone, too. If someone says you need more categories, go ahead and sort that person under ”bad”.

When it comes to sorting your classes, here’s a foolproof heuristic: if it only has methods, it’s clearly a working class. If, on the other hand, it owns properties, or maybe inherits from another class, it’s obviously bourgeoisie and has to go. Functional programming all the way!

Collectivize

Access control is a blessing in disguise. It makes refactoring a breeze. Just search for the word private in your project. Now you’ll have uncovered most of what is wrong with the system. All private properties will stick out like sore thumbs in all their individualistic glory, ready to be axed. Substitute the word public everywhere, and smell the morning air of the collectively owned future!

Peer Review

This is truly important. If you weren’t doing it before, you need to start now. It’s by far the best, and cheapest, way to discover problems in the system. Peer review, as is understood by the name, means reviewing peers, not their work. Otherwise it would be called peer work review, or something. So make sure all participants stay vigilant towards each other. Anyone deviating from the overarching ideology must be reported, whether neighbour, friend or spouse!

Global state

Is there such a thing? It sounds too good to be true! As long as it’s a socialist state, global must obviously be a good thing. It just means the whole world can enjoy the new system!

Conclusion

This is a great way to refactor code with problems. If you play your refactoring cards right, you could have your system running just as smoothly as any of the previously refactored societies … I mean codebases of the world. And if other developers don’t agree, you know where to send them…

--

--