By Xavier Shay

Code Safari: End of the Road

By Xavier Shay

This is my last post in the Code Safari series here on Ruby Source. I have really enjoyed writing it and trying out a new format which I hope you have found useful. For my concluding article, I want to leave you with some tips for planning your own safari since that is really what the whole series has been about: Not your typical how-to, but a glimpse into the work flow that I and many other developers use everyday to figure out how our tools work.

Here are five practices that you should incorporate in to your day-to-day craft.

Read code

I never use a gem or third-party library without perusing its source code first. With the easy availability of GitHub and gem unpack there is no reason not to. Not only do you learn a lot by reading code, but you also verify that the code does what it claims in a way that is suitable for your project.


Never cargo-cult

Cargo-culting is the practice of copying a technique or idiom that you have seen without understanding it. Ruby is full of techniques, good and bad, that can be confusing the first time you come across them.

<Hash[%w$he ll? [iuo]$.map {|x| [x, "hello"[/#{x}/, 0]] }]
class &lt;&lt; "abc"; self; end

Always open up irb to validate your assumptions about what is going on.

Teach others

I firmly believe that if you can’t explain a topic to someone else then you don’t fully understand it. Teaching comes in many forms: writing, pairing, whiteboarding, but all of them involve generalizing and abstracting concepts that is an essential step in really understanding what is going on.

If you don’t have a blog, that is the easiest way to start. Many people worry that they don’t have anything interesting to say, but this is irrelevant. Taking the time to write up a new technique you’ve learned or a bug you found forces you to make sure you explored it fully, and solidifies your understanding.

Take notes

I keep a pen and a notebook on my desk that I write in anything that interests, confuses, or angers me as I go about my programming. I can revisit this list later without being distracted from my current task. This is so important for maintaining focus, but also for giving you a rich palette of choices to investigate when you next have down time (and there’s no excuse for not having downtime!)

Nothing is too big

Code can be intimidating especially when you are learning, but don’t be afraid of seemingly impenetrable code bases. There is always a next step within your grasp, even if it’s just reformatting some indenting, or validating an assumption with a puts statement. Ruby is particularly friendly to this, since you can dive right down into even your system gems with only a text editor and modify them temporarily to figure out what is going on. A handy tool for this is the $LOAD_PATH and $LOADED_FEATURES global variables, which will tell you exactly what has been loaded and where from.

Wrapping Up

In closing, I leave you with perhaps the most mind-blowing use of Ruby I have ever seen. It’s a beautiful work from Yusuke Endoh, the author of the underscore library I covered last week, named Qlobe:

It’s a ruby program that outputs a rotated version of itself everytime you run it. In other words:

ruby qlode.rb | ruby | ruby

How does it work? You’ll just have to go on safari…

The most important and interesting stories in tech. Straight to your inbox, daily. Get Versioning.
Login or Create Account to Comment
Login Create Account