EmmaTech

  • Emma Home
  • Emma Blog
  • Job Openings
  • RSS

Applying minimalism to development

Simplify everything

Josh Mock 20 May 2011 Python time workflow 4 Comments

Lately I’ve found sat­is­fac­tion in fol­low­ing a min­i­mal­ist lifestyle. Having a lot of stuff isn’t all it’s cracked up to be and more often than not dis­tracts me from how I really want to spend my time. My desk has been described as “spar­tan” and led to more than one men­tion that a clean desk is a sign of insan­ity. (Is it really? That’s a dis­cus­sion for another day.)

The idea behind min­i­mal­ism is that you only keep what you need, and any time you con­sider adding to your col­lec­tion of things, ques­tion whether it’s actu­ally needed. Anything beyond what’s nec­es­sary is clut­ter; more­over, it’s a dis­trac­tion that requires energy to main­tain. This idea applies to per­sonal orga­ni­za­tion and con­sumerism, but also to development.

Python is a great lan­guage for aspir­ing min­i­mal­ists. The Zen of Python could eas­ily dou­ble as the zen of min­i­mal­ism given minor edits. “There should be one — and prefer­ably only one — obvi­ous way to do it” is min­i­mal­ist gold.

It’s easy for code to get messy. Our brains don’t think like com­put­ers (if yours does, you might be an autonomous robot), and ideas trans­lated into code often come out jum­bled. Add more than one brain and the jum­ble grows expo­nen­tially. But if we build in some time to revisit and ques­tion how we wrote some­thing, we can improve read­abil­ity, main­tain­abil­ity and often the per­for­mance of our code.

For exam­ple, dur­ing a recent refac­tor of my own hastily-written code, it took me mul­ti­ple glances — and scrib­bling down a truth table — to real­ize 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 log­i­cally equiv­a­lent to this:

setting1 = (len(list1) > 0)
setting2 = (len(list2) > 0)

I’m sure the first way made sense as I was writ­ing it; I was prob­a­bly adding con­di­tions one at a time as they were needed. But I should have gone back before com­mit­ting my changes and noticed some­thing like that.

During the same refac­tor, a more broad set of changes reduced six Django views down to two, elim­i­nat­ing redun­dant data­base calls, mak­ing it eas­ier to imple­ment a Django form and remov­ing almost all need to store data in ses­sion. Refactoring felt good, but it should have been done that way in the first place. Keeping a min­i­mal­ist men­tal­ity from the start would have made my refac­tor­ing unnecessary.

And so I’ve lately been slow­ing down as I code. I run through a men­tal check­list as I go and proof­read every changed line a few times before I com­mit it. It may take more time now, but I can save my team time later if the code is eas­ier to mod­ify and main­tain. I’m con­tin­u­ally ask­ing myself ques­tions like these:

  • Is every vari­able in this func­tion nec­es­sary? Is any­thing redundant?
  • Could a list com­pre­hen­sion replace this loop?
  • Could an inline con­di­tional replace this if/else block?
  • Does an exist­ing library or mod­ule already do this?
  • Could I use or extend a util­ity func­tion to han­dle this?
  • Can these sim­i­lar data­base calls be reduced into one trans­ac­tion with­out being confusing?
  • Can some sim­ple func­tional pro­gram­ming reduce a few lines of code?

Tell me what you think. Can you apply any of these ques­tions to your code? Is there any­thing I’ve missed? I’d love to hear what’s work­ing for other min­i­mal­ists out there.

4 comments

RufflesDebs commented:

2011-05-24, 10:44

Technically speak­ing I have no idea what you’re talk­ing about. You lost me at cod­ing BUT the prin­ci­ple is great and applies to so much in life.
The cod­ing you dis­played looks like my To Do Lists which should really end with — Write a neater To Do list. :D

Debs
x

Josh Mock

Josh Mock commented:

2011-05-24, 11:04

Awesome, Debs! Glad you can still apply some min­i­mal­ism to your to-do lists, even if the code part didn’t make a lick of sense to you. :)

Ethan Brown commented:

2011-06-22, 14:50

I’ve found that min­i­miz­ing stuff isn’t for me, really — I’ve got too many hob­bies for that! However, some of the con­cepts you touch on have def­i­nitely served me well, like think­ing hard about new things you acquire and how (and if) they fit into your life.

I have mixed feel­ings about min­i­mal­ism in pro­gram­ming. For the most part, I approve, but like any­thing, it can be taken too far. If you mind­lessly wor­ship at the alter of min­i­mal­ism, a Perl pro­gram that does in three lines what nor­mally takes 100 lines would be the height of excel­lence. But if those three lines are a incom­pre­hen­si­ble, unob­vi­ous, unmain­tain­able mess, min­i­mal­ism is not serv­ing its own pur­pose. I guess what I’m say­ing is that com­pact­ness does not always equal minimalism.

Your rev­e­la­tion about your if/else code brought to mind Karnaugh Maps (remem­ber those from uni­ver­sity? If not, there’s a good arti­cle on Wikipedia). Certainly, I think your revised exam­ple is much cleaner, and I would much rather see that if I was review­ing your code, but I could con­struct a coun­terex­am­ple where I com­pact some code and make it *less* comprehensible.

When I read your post, I think I get the spirit of what you are say­ing — min­i­mal means “unclut­tered” and “ele­gant” — I just want to point out that one could, instead, take min­i­mal to mean “com­pact”, which would miss entirely the spirit of your post.

Overall, a very thought­ful post. Well done, Josh!

Josh Mock

Josh Mock commented:

2011-06-22, 15:01

Great point, Ethan. As with most things, all prac­tices should be in mod­er­a­tion. Anyone who’s debugged Javascript in Firebug or Chrome knows that a mini­fied JS file is pretty much impos­si­ble to fix.

Thanks for the feedback!

Leave a comment

Click here to cancel reply.

About Josh Mock

Josh Mock

Josh is a web developer by day and an amateur DJ and music writer the rest of the time. He recently moved to Nashville from California and is looking for a good burrito.

Read more from Josh

Emma Tech on Twitter

    Follow Emma Tech »
    Help wanted

    • Popular Tags

      Python12 api7 UX5 conferences4 postgres4 workflow4 time4 javascript3 PHP3 jQuery3 tools3 editors2 travel2 server maintenance2 Git2 maintenance windows2 Haml1 Frank1 Ruby1 CSS1 PyCon1 office1 Sass1 downtime1 post‑mortems1 cgit1 books1 Trac1 collaboration1 community1 Twitter1 Facebook1 OAuth1 coding1 cool sites1 Redis1 github1 objects programming refactoring1 integration1 salesforce1 usability testing1 Social Posting1 music1 productivity1 bugs1 TextExpander1 san francisco1 Convore1 Vim1 releases1 legacy data1 HTML1 reading1 Django1 PgCon1 testing1 TDD1

    Emma is a member of the Email Sender & Provider Coalition and the Messaging Anti-Abuse Working Group.

    Copyright © 2003 - 2012 Emma.
    All rights reserved.

    • Get Emma's Newsletter
    • Visit the Emma Blog
    • @emmaemailtech on Twitter
    • @emmaemail on Twitter
    • Emma on Facebook

    Emma's email marketing makes communicating simple and stylish.
    Inquire now for more details.