Single Responsibility, Duplication, and Minimalism

Having just enough is called Minimalism.

I was watching this documentary on Netflix called Minimalism. It has featured multiple people who claim to be minimalist, talking about how minimalism has changed their lives.

Let me start off by saying that everyone should watch this documentary. It highlights rather vividly how pathetic materialism is making us and how it is leading the future of mankind to disaster. As distinctly as it has portrayed the issue of materialism, I think it failed to propose a good practical solution to it.

The documentary featured this guy (practically homeless) who claims to own only 51 items. It mentioned this minimalistic living room setup (the chair does not look comfortable to me). It took examples of minimalist people living in tiny houses on wheels or people living in the homes where they have to pull the bed down or move the walls for more space. Honestly, I don’t think me or any one I know can adopt any of these solutions in order to pursue minimalism. These solutions are simply overwhelmingly impractical.

There is no doubt that materialism has become one of the biggest problems of our generation with social media booming and everyone trying hard to show off their possessions, with the introduction of Fast Fashion and the rise of thousands of YouTubers, swanking around in their ostentatious houses and ornate closets, encouraging us to buy their favorite things (they do monthly favorites videos for god’s sake!) and the fact that we all are buying into this.

As materialism is becoming more noticeable, minimalism is becoming the new fashion. People have YouTube channels about minimalism (obviously!). Again they are trying to sell us stuff – stuff for the minimalist! Or people are coming up with the extreme versions of minimalism, like the guy with only 51 items living on the streets. Can you imagine if all of us start to live on streets or had that one chair in our living rooms? This is not being minimalist. This is being torturous to yourself.

Programmer’s Take

Amid the confusion of how to approach minimalism, I think we programmers have figured it out. Programmers are always trying to produce simpler and compact code. Simpler doesn’t mean that the program has less number of features, simpler means it has less number of lines of code whilst providing same functionalities.

Just as eliminating a feature is not the means to achieve reduced lines of code, dismissing the way of normal living is not a solution to materialism. You don’t have to stop inviting your friends over because you are a “minimalist” and have no couch.

So what makes a code longer than it should be if it is just implementing a functionality? If you are a programmer, you must be thinking – “Duh! Duplication”. Yes, same lines of code to achieve the same thing in multiple places is what makes the code messier. Duplication for programmers is a synonym for materialism. Software engineers are constantly working to figure out ways to reduce redundancy in the code. Every single design principle, every single design pattern has been created to reduce duplication in some way or the other.

Don’t Repeat Yourself a.k.a DRY principle tells programmers that be mindful of duplication. I have talked about DRY in my previous blog. I am still going to define it here because as they say ‘Repetition is key to learning’

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system

The irony is when you become conscious of something, it will start appearing everywhere. Everything looks like duplication, simple things like calling a method at two places or invoking getters and setters multiple times. In order to remove duplication, we start writing more generic methods and end up overloading a piece of code with more functions than it should perform.

It is the similar situation if you start wearing the same pair of shoes to work, to the beach and to the gym, because having another pair of shoes will be duplication (i.e. materialism). Now think what will happen if you lost these shoes? Three of your activities will be impacted. You are overloading responsibilities on the pair of shoes.

It is impossible to write code by only following DRY. You need something to balance out extreme implications of DRY.

Single Responsibility Principle or SRP, the ‘S’ from SOLID principles, comes to the rescue. This is what Uncle Bob (Robert C. Martine) says about SRP

The Single Responsibility Principle (SRP) states that a class or module should have one, and only one, reason to change. This principle gives us both a definition of responsibility, and guidelines for class size. Classes should have one responsibility—one reason to change.

SRP says that every method and every class should have one and only one purpose. A class should only change if that purpose changes and for no other reasons.

This solves the problem of responsibility overloading, right? Yeah, SRP will tell you to buy three different pairs of shoes for gym, work, and beach. But as easy as SRP sounds, it can go south very quickly. While buying shoes for work, you would think – wait a minute what about casual Fridays? And what about the shoes when I go on dates? What about the times when I go fishing? What about the shoes with my long dresses? for short dresses? What about…? SRP will say okay to all these shoes because each pair of shoes has the “single responsibility”. And before you know it, you have ten pairs of shoes.

The first step in implementing SRP is to figure out that one responsibility. And it is harder than you think. There is a very fine line between the right implementation of SRP and duplication in disguise.

The extreme application of SRP ends up resulting in overflowing closets and excessive utilization of DRY makes us the homeless guy with 51 items. There has to be some balance. If you combine both of them something like this comes up

SRP tells you that for every need, you should have one item. And DRY tells you that you can have the item as long as you don’t already have an item serving the exact same purpose.

SRP and DRY keep each other from reaching boundary conditions. While SRP tells you that it is not okay to wear the same outfit to work and to the gym, DRY tells you not to buy seven different gym outfits for every day of the week. While SRP hates shampoo with conditioner in one bottle, DRY doesn’t want you to buy separate shampoos and conditioners for volume, frizziness, and dryness. While SRP says it is okay to have separate towels for the beach, DRY will tell you not to have 11 categories of towels (guest, fancy guest… Friends fan? anyone?).

And of course, YAGNI (You Ain’t Gonna Need It) forces you to justify the need in the first place.

Why be minimalist?

In software development world, we are striving to reduce the number of lines of code, number of classes and methods while maintaining the functionalities and quality of the application. It is very easy to write a line of code. You just need a bunch of words, no raw material is required. Then why every programmer (at least good ones) is constantly trying to not write those bunch of words? Does it make the life of the programmer who is writing it easier?

Umm not really! If anything, it takes a lot of careful analysis and hours of staring at the code to make sure there is no unnecessary code written. The constant picking of your brain to figure out a better and simpler way to write it. All of this is done because every line we write has consequences. A line of code is only written once but will be read by many and maintained for years. It will be affecting lives of the other programmers long after the writer of the code has gone. The writer’s life can become easier as a side effect, but the motive behind coding responsibly is bigger than that. It is about making sure the life of the team who is involved currently and the future support team is not miserable because of the code you have written.

Similarly, buying any material object comes with its own consequences. And these consequences are way bigger than the ones in the software world. Every piece of cloth you buy does not only increase clutter in your closet and adds to everyday struggle of deciding ‘what to wear’,  it also affects the entire cycle of garment production from the cotton farmers to the garment makers in Bangladesh and other third world countries, to the people living in the areas where these clothes get dumped long after you have gotten rid of them.

Being minimalist is not about saving money. It is not about decluttering or being mobile. It is not driven by how rich or poor you are. These can be side effects of being minimalist. People say being a minimalist is about having only the things you love, the possessions that make you happy. Well, you would be surprised to know just how many things can trigger that dopamine!

Being minimalist is a social responsibility. It is about being aware of the fact that every purchase you make affects a lot of people. It is about making the decision to not buy things that you don’t need even though you can very easily afford it and everyone around you has it. And being okay with that decision. Not sad, not happy, just okay. A wise person once told me “Don’t get attached to material objects”. I have been carrying this thought ever since.

Don’t buy things you don’t need (YAGNI), there is nothing wrong with buying things for your convenience (SRP) and do not buy another item to serve the same purpose (DRY). Remember that every item you buy has bigger consequence than you can ever imagine.

P.S. – If you are addicted to social media, before buying anything just ask yourself – “Would I still be buying it if I never ever post any of its pictures on social media?”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s