Goodbye, Clean Code

It’s a Phase

Obsessing with “clean code” and removing duplication is a phase many of us go through. When we don’t feel confident in our code, it is tempting to attach our sense of self-worth and professional pride to something that can be measured. A set of strict lint rules, a naming schema, a file structure, a lack of duplication.

You can’t automate removing duplication, but it does get easier with practice. You can usually tell whether there’s less or more of it after every change. As a result, removing duplication feels like improving some objective metric about the code. Worse, it messes with people’s sense of identity: “I’m the kind of person who writes clean code”. It’s as powerful as any sort of self-deception.

Once we learn how to create abstractions, it is tempting to get high on that ability, and pull abstractions out of thin air whenever we see repetitive code. After a few years of coding, we see repetition everywhere — and abstracting is our new superpower. If someone tells us that abstraction is a virtue, we’ll eat it. And we’ll start judging other people for not worshipping “cleanliness”.

I see now that my “refactoring” was a disaster in two ways:

Firstly, I didn’t talk to the person who wrote it. I rewrote the code and checked it in without their input. Even if it was an improvement (which I don’t believe anymore), this is a terrible way to go about it. A healthy engineering team is constantly building trust. Rewriting your teammate’s code without a discussion is a huge blow to your ability to effectively collaborate on a codebase together.

Secondly, nothing is free. My code traded the ability to change requirements for reduced duplication, and it was not a good trade. For example, we later needed many special cases and behaviors for different handles on different shapes. My abstraction would have to become several times more convoluted to afford that, whereas with the original “messy” version such changes stayed easy as cake.

Am I saying that you should write “dirty” code? No. I suggest to think deeply about what you mean when you say “clean” or “dirty”. Do you get a feeling of revolt? Righteousness? Beauty? Elegance? How sure are you that you can name the concrete engineering outcomes corresponding to those qualities? How exactly do they affect the way the code is written and modified?

I sure didn’t think deeply about any of those things. I thought a lot about how the code looked — but not about how it evolved with a team of squishy humans.

Coding is a journey. Think how far you came from your first line of code to where you are now. I reckon it was a joy to see for the first time how extracting a function or refactoring a class can make convoluted code simple. If you find pride in your craft, it is tempting to pursue cleanliness in code. Do it for a while.

But don’t stop there. Don’t be a clean code zealot. Clean code is not a goal. It’s an attempt to make some sense out of the immense complexity of systems we’re dealing with. It’s a defense mechanism when you’re not yet sure how a change would affect the codebase but you need guidance in a sea of unknows.

Let clean code guide you. Then let it go.

The Conservative Soul: Fundamentalism, Freedom, and the Future of the Right Paperback – October 9, 2007

if the acceptance and love of others as they are is the essence of Christianity, then the acceptance of our loneliness and doubt in a world far beyond our understanding is the core of all non-fundamentalist religion.

pg 219  Andrew Sullivan, The Conservative Soul

 

What religion can be at its most sublime is the fusion of that wonder we should really feel all the time in the presence of God. What religion can be at its most sublime is the fusion of that wonder with practical life. It is the marriage of the poetic and practical modes of experience. This does not require the imposition of fixed rules and doctrines, although they may be helpful guides from time to time.  It requires a constant reimagination of the potential of life  lived on earth as if it were heaven. It requires letting go of our desire not to let go. Jesus saw it in children. One of his most radical teachings was the notion that only if we become like children will we enter the kingdom of God.

Children love rituals, and their games are full of them. Perhaps because they are not yet fully formed, every moment matters more. We older types have sometimes become inured to the wonder and mystery of everything.

pg 222

 

These moments may come upon us when we least expect them. We may see flashes of eternity in the simple grin of a child in a game of hind and seek, in the approach of the tide on an autumn  afternoon, in the eyes of a lover in sex, or in grandmother’s ritual– but we know them when we see the. The key is to be open to them, because they happen all the time, all around us. But we are too “busy” to notice.

The opposite of this kind of faith is fundamentalism: the constant recourse to abstraction and authority or text.

The Rise of the Amnesty Thugs

Franco was an unauthorized immigrant who had been working in this country for over a decade. His wife, Anne, is from a Pennsylvania Dutch family that has been in this country for generations. They were married in 2013 and have three American children, Max, Javier and Valentina.

In the spring of 2017, Franco got in a minor traffic accident near his Pennsylvania home. A few weeks later as he was leaving for work, agents from Immigration and Customs Enforcement swarmed him, took him away and deported him to Guatemala.

.. This is an example of ICE going after a perfectly productive member of society. I got the anecdote from a series of reports that Deborah Sontag and Dale Russakoff did for ProPublica and The Philadelphia Inquirer. They found that 64 percent of the immigrants arrested by ICE in the agency’s Philadelphia region had no prior criminal conviction.

.. There are 11 million unauthorized immigrants in this country. Every past administration has used some discretion in targeting whom to deport. They targeted those who were destroying society, not building it. They tried to take account of particular contexts, and they tried to show some sense of basic humanity.

.. today, discretion and humanity are being stamped out. The Trump administration has embraced a “zero tolerance” policy. In practice that means that all complexity has to be reduced to uniformity. Compassion is replaced by a blind obedience to regulations. Context is irrelevant. Arrests are indiscriminate. All that matters is that the arrest numbers go up, so human beings in the system are reduced to numbers.

.. The Trump administration immigration officials have become exactly the kind of monsters that conservatism has always warned against.

For centuries, conservatives have repeated a specific critique against state power. Statism, conservatives have argued, has a tendency to become brutalist and inhumane because a bureaucracy can’t see or account for the complexity of reality.

.. Statist social engineering projects cause horrific suffering because in the mind of statists, the abstract rule is more important than the human being in front of them. The person must be crushed for the sake of the abstraction.

.. People like Stephen Miller are not steeped in conservative thinking and do not operate with a conservative disposition. They were formed by their rebellion against the stifling conformity they found at liberal universities. Their primary orientation is not to conservative governance but to owning the libs. In power they take the worst excesses of statism and flip them for anti-liberal ends
.. Here’s how you can detect the anti-liberal trolls in the immigration debate: Watch how they use the word “amnesty.”
.. Any serious reform has to grapple with tangled realities, and any real conservative has an appreciation for that complexity. But if you try to account for that complexity before an anti-immigration troll, he or she will shout one word: Amnesty!
.. This is what George Orwell noticed about the authoritarian brutalists: They don’t use words to illuminate the complexity of reality; they use words to eradicate the complexity of reality.
.. Look at how the Republican candidates for the G.O.P. Senate nomination in Arizona answered questions about a provision to keep families together at the border. They responded with inhumane abstractions: “I try not to get swayed by what the emotions are or the pressure
.. “Compromising on the rule of law to grant amnesty to millions of illegal immigrants is the wrong path to take,”
.. “Amnesty” has become a club the trolls use in their attempt to stamp a rigid steel boot on the neck of the immigration debate. It’s the sign of a party slowly losing its humanity.