Friday, May 28, 2010

Attitude in Programming...

Jonathan Edwards has an interesting post about the importance – the primacy, really – of attitude in programming.  The basic message is that when there's a choice between simple, readily digestible way to do something and a more complex but also more elegant or beautiful (to a sophisticated or accomplished programmer), then choose the simple way every time.  Making those choices for the simple means the overall piece of software will be less complex, more bug-free, more easily modified, etc. 

I couldn't agree more, but I don't the picture is quite as clear as he paints it (and I suspect Edwards would agree).  For example, one of the tensions in making such choices lies with deciding exactly what is simple and clear.  I had an experience a couple of years ago that illustrates this.  I'd written a small piece of code (in Java) that made use of the exclusive-or operator (“^”).  To me, that was obvious, simple, and clear – and obviously simpler than the alternative.  But my colleagues disagreed, because they didn't know that operator.  To them, writing (a && !b) || (!a && b) was simpler and clearer than a ^ b (where a and b are boolean values) which was a huge surprise for me!  I eventually settled on the code a != b, which satisfied both of us.  The point is that it's not always easy to decide exactly what constitutes simple and digestible – but that doesn't mean it shouldn't be your goal...

No comments:

Post a Comment