You Can Learn a Lot From Shaving a Yak
The following is a guest post by George Lin and originally appeared onĀ his blog.Ā George is currently a student at The Flatiron School. You can follow him on TwitterĀ here.
Ā On the third day of class, we learned a term called āyak shavingā. The idea is that you want to do something, letās say change a lightbulb, but that ends up requiring you to do something else, which in turn requires you to do something else, which requires you to do something again⦠After diving into subtask after subtask, eventually you find yourself shaving a yak when all you wanted to do was change your lightbulb!
Etymology: the term is thought to have been coined at the MIT AI Lab circa 2000, as inspired by an episode of Ren & Stimpy. Here are some definitions from various sources:Ā MIT,Ā Urbandictionary,Ā Seth GodinĀ (who helped popularize the term)
I didnāt think much about the term until pretty recently. In the last 2 weeks or so, as Iāve been diving heavily into code, Iāve found myself shaving yaks constantly ā I can see why itās a āthingā in programming now!
Case in point ā the jukebox. As my teammates can attest, Iāve been building a command-line interface jukebox which when given a list of songs, will retrieve the songsā artists and genres, and allow the user to browse or choose by category and select a song to āplayā (it only displays the song & doesnāt actually play it yet, haha). Well technically, this was an assignment everyone had to do, but since I liked the idea I decided to take it a lot further. (Also, to order to generate a song list, we parsed a directory for mp3 files and built a library of artists, songs, and genres)
My current version of the CLI jukeboxĀ can not only browse by āartistā, āsongā, or āgenreā, but it can also search by artist, song, or genre, and whatever the results are of the current search or browsing results, you can keep entering input to further filter results, as well as choose a result by number (thanksĀ NingĀ for some of the inspiration!)
Here are some examples of yak shaving while making the CLI jukebox:
In order to get the program to understand so many different kinds of user inputs, I ended up having to learn regular expressions (RubularĀ is awesome!). Specifically, valid commands that the program understands are stored in class constant:
This allows for the program to understand the input āartist(s)ā, āsong(s)ā, āgenre(s)ā, as well as the input āartist [name or number]ā, āsong [name or number]ā, āgenre [name or number]ā.
Here is what my code for seeing whether or not a valid command is recognized looks like:
This doesnāt work though. After some banging my head on the wall, I ended up reading theĀ āgrepā documentation in the Ruby Enumerables module, and discovered the problem:
Simple enough. We open the class and give it a new method grep2:
After creating this program on my own computer, I wanted to import this to the web so that it could run as a CLI āweb appā over the internet. I was inspired by a few command-line interface websites:Ā xkcd,Ā goosh, After many futile attempts at finding an answer which made me question my google-fu, I finally found something reasonable which had been staring at me in the first page of google results: a Ruby gem calledĀ Rack Webconsole! After installing, more banging my head on the wall and finagling, I finally got it to work:Ā
Now I need to learn how to get āputsā and āgetsā to work in the webconsole interface instead of on the server-side console:
I also learned aboutĀ a little bit about XRSF, a way for bad people to hack into your website, as I was learning about Webconsole. In retrospect, using this gem probably isnāt the best idea to use in production, though itās pretty awesome in development. Maybe Iāll learn enough javascript by looking at the source code of sites like xkcd and goosh to make this work someday.
Enjoying the view and striving for the destination
Thereās always more to learn, and to do something I thought would be so simple ended up requiring hours and hours of banging my head on the way. However, in retrospect it was all a great learning experience and helped me become a better coder, as I suspect yak shaving can oftentimes be.
Itās the journey that matters, not the destination. However, a program that doesnāt work right isnāt useful either. So I guess both are important ā enjoy the view along the way, but to learn the most, donāt stay satisfied until you reach the destination.












