# Don’t shave that yak – God loves lazy programmers

I just wasted four days of my life on something completely worthless. It started off innocently enough, I wanted to take a cloud of data points and display them as a nice heatmap.

The Story

Hmmm, sounds just like the mesh creation I used to do when I was back in games, so let's dust off that Computational Geometry textbook and write a Delaunay Triangulator. Sweet, there's even an example in Javascript I can adapt to Actionscript. Awesome, it all works on my test data. Oh, it's O(n^2) in complexity, so it doesn't work so well on my larger test of 1,000 points, and it will take the lifetime of the universe to process the 30,000 points I need it to.

No worries, I'm a clever chap, I'll dig through the literature and find a better algorithm. They all seem to be either too complex to implement easily or don't have the performance characteristics I need. I don't need a strict Delaunay arrangement, so I should be able to brew up my own divide-and-conquer version that uses the exact algorithm on sub-sets of the points and then stitches them back together with Delaunay-like strips.

Huh, looks like there's a bug in the convex hull creation code I wrote. And another. And another. Arrrggh! I need a better way of visualizing what's going on, so I'll build a canvas-based web page that lets me view the output of my algorithm. And then I need to…

What? It's Saturday afternoon? Where did my week go! And why am I still banging my head against this code? What was I trying to do again? Oh yes, display a heatmap of these points. So why have I been debugging convex hull merging code for the last two days? There must be a simpler way.

<… two hours pass …>

There we are, I just adapted some point blob rendering code I was already using, so I don't have to worry about triangulating a massive cloud of points, I just throw blobs at the screen and build up the image. Works great. Now I just have to write a blog post to remind myself once again – *Never Shave a Yak!*

The Lesson

Yak shaving is a term I first ran across in the Jargon File, and it stuck in my head because it's so common and so dangerous in programming. It's when you're working on a task because you need to do it to get something else done, which you're doing to complete another job, and so on up a long dependency chain towards your real goal. This happens a lot when you're coding, and just like my story each step is very logical but you ultimately end up wasting massive amounts of time on something that has very little effect on what you really want to do.

I swear that the biggest reason I'm a more effective programmer now than when I was 20 is that I'm better at spotting when I'm shaving a yak, and finding another way. The biggest clue is when I'm working too hard. I went into a serious deep dive for the last few days, staying up late, skipping dog walks and getting way behind on my emails (sorry to anyone waiting for a reply!). If I'm making progress on something core this sort of crunch time is actually an energizing process as long as I don't keep it up too long. In this case I was feeling frustrated, and looking back it was largely because it was a peripheral task that at some level I knew didn't have to be solved.

There's already lots of other reasons to embrace lazy programming. Fewer lines of code means fewer bugs. The best route to an easy life is writing solid code that doesn't require constant maintenance, and is documented enough so people don't bug you with questions. Harness your inner laziness to spot yak shaving too, and find a simpler way when you're spinning your wheels on a peripheral task.