There was an error in this gadget

Friday, July 13, 2012

Writing great software (or anything) means managing your energy.

I've learned one big thing over the past weeks of writing Objective-C (a.k.a iOS or iPhone) code for the first time.  When you feel like the thing you're staring at should work and you don't know why, STOP WORKING!

I have a theory behind this rule.  I borrowed it from Tony Schwartz. The theory is after about 90 minutes the average human starts to lose focus and higher-level cognitive functions drift.  Most artists, developers, writers - you cats - are above average, so maybe you get two hours at the outside.  So after about two hours the extra-ordinary human loses the ability to differentiate between minute details, which is what these silly, frustrating, "why-can't-I-figure-this-blasting-thing-out" problems are all about.

The solutions to silly software problems that make developers like me crazy end up being things like:

  • I included a source file instead of a header file.
  • The index was 0 instead of 1.
  • The name of a variable was misspelled - "tacoTrock" instead of "tacoTruck".  
  • I accidentally overloaded a method name as a variable.
These are all really simple, dumb things.  Good defensive programming can help you avoid them.  For example, using a great IDE (integrated development environment) that has autocomplete and text highlighting will help you avoid spelling errors.  Never using "set" to start a method name helps avoid overloading implicit setters/getters.  Using "isFoo" for boolean variables helps you avoid getting confused by true/false states and "didFoo" is a great naming convention for callbacks/delegates.  


But these practices are not enough; even if you write perfect code with perfect style, you're gonna hit a wall.


When you hit the wall, walk away.  Over the past month or so I've tried to step away for 10-20 minutes when I hit the wall.   When I return to work I've found the answer in less than 15 minutes.  Every. Single. Time.  And when I don't step away?  I waste upwards of an hour and don't get the answer.


Every. Single. Time.


Maybe I'm insane or just far below average, but I doubt it.  Rather, I think we all have to manage our energy very carefully.  Skeptical?  Just try it - run your own experiment.  


If you're a type-A overachiever you will probably feel bad about not working during those 10-20 minutes.  I know I still struggle with these feelings.  So try saying, 


"I am running an experiment.  Good science makes for good products, so practicing this good science for two weeks is a good idea.  At the end of two weeks I will evaluate my progress.  In the meantime, I can't argue with how nice it is to walk up to the coffee shop in the sun..."
If you wonder why I'm at Verite most days between 2:30 and 4:30 it's because A) the Red Sox don't start playing until 4:15PST most days and B) I generally need that walk-to-the-coffee-shop break 2 hours after lunch!


Want to know more about managing your energy?  I wrote about it in Shipping Greatness, and you can also read Tony Schwartz's book.