Applying minimalism to development
Simplify everything
Lately I’ve found satisfaction in following a minimalist lifestyle. Having a lot of stuff isn’t all it’s cracked up to be and more often than not distracts me from how I really want to spend my time. My desk has been described as “spartan” and led to more than one mention that a clean desk is a sign of insanity. (Is it really? That’s a discussion for another day.)
The idea behind minimalism is that you only keep what you need, and any time you consider adding to your collection of things, question whether it’s actually needed. Anything beyond what’s necessary is clutter; moreover, it’s a distraction that requires energy to maintain. This idea applies to personal organization and consumerism, but also to development.
Python is a great language for aspiring minimalists. The Zen of Python could easily double as the zen of minimalism given minor edits. “There should be one — and preferably only one — obvious way to do it” is minimalist gold.
It’s easy for code to get messy. Our brains don’t think like computers (if yours does, you might be an autonomous robot), and ideas translated into code often come out jumbled. Add more than one brain and the jumble grows exponentially. But if we build in some time to revisit and question how we wrote something, we can improve readability, maintainability and often the performance of our code.
For example, during a recent refactor of my own hastily-written code, it took me multiple glances — and scribbling down a truth table — to realize that this:
if len(list1) > 0 and len(list2) > 0:
setting1 = True
setting2 = True
else:
if len(list1) > 0:
setting1 = True
else:
setting1 = False
if len(list2) > 0:
setting2 = True
else:
setting2 = False
is logically equivalent to this:
setting1 = (len(list1) > 0) setting2 = (len(list2) > 0)
I’m sure the first way made sense as I was writing it; I was probably adding conditions one at a time as they were needed. But I should have gone back before committing my changes and noticed something like that.
During the same refactor, a more broad set of changes reduced six Django views down to two, eliminating redundant database calls, making it easier to implement a Django form and removing almost all need to store data in session. Refactoring felt good, but it should have been done that way in the first place. Keeping a minimalist mentality from the start would have made my refactoring unnecessary.
And so I’ve lately been slowing down as I code. I run through a mental checklist as I go and proofread every changed line a few times before I commit it. It may take more time now, but I can save my team time later if the code is easier to modify and maintain. I’m continually asking myself questions like these:
- Is every variable in this function necessary? Is anything redundant?
- Could a list comprehension replace this loop?
- Could an inline conditional replace this
if/elseblock? - Does an existing library or module already do this?
- Could I use or extend a utility function to handle this?
- Can these similar database calls be reduced into one transaction without being confusing?
- Can some simple functional programming reduce a few lines of code?
Tell me what you think. Can you apply any of these questions to your code? Is there anything I’ve missed? I’d love to hear what’s working for other minimalists out there.
4 comments
Leave a comment

RufflesDebs commented:
Technically speaking I have no idea what you’re talking about. You lost me at coding BUT the principle is great and applies to so much in life.
The coding you displayed looks like my To Do Lists which should really end with — Write a neater To Do list. :D
Debs
x
Josh Mock commented:
Awesome, Debs! Glad you can still apply some minimalism to your to-do lists, even if the code part didn’t make a lick of sense to you. :)
Ethan Brown commented:
I’ve found that minimizing stuff isn’t for me, really — I’ve got too many hobbies for that! However, some of the concepts you touch on have definitely served me well, like thinking hard about new things you acquire and how (and if) they fit into your life.
I have mixed feelings about minimalism in programming. For the most part, I approve, but like anything, it can be taken too far. If you mindlessly worship at the alter of minimalism, a Perl program that does in three lines what normally takes 100 lines would be the height of excellence. But if those three lines are a incomprehensible, unobvious, unmaintainable mess, minimalism is not serving its own purpose. I guess what I’m saying is that compactness does not always equal minimalism.
Your revelation about your if/else code brought to mind Karnaugh Maps (remember those from university? If not, there’s a good article on Wikipedia). Certainly, I think your revised example is much cleaner, and I would much rather see that if I was reviewing your code, but I could construct a counterexample where I compact some code and make it *less* comprehensible.
When I read your post, I think I get the spirit of what you are saying — minimal means “uncluttered” and “elegant” — I just want to point out that one could, instead, take minimal to mean “compact”, which would miss entirely the spirit of your post.
Overall, a very thoughtful post. Well done, Josh!
Josh Mock commented:
Great point, Ethan. As with most things, all practices should be in moderation. Anyone who’s debugged Javascript in Firebug or Chrome knows that a minified JS file is pretty much impossible to fix.
Thanks for the feedback!