Tuesday, March 25, 2008

My ctags lightning talk

Last week at the Raleigh.rb we had an evening of lightning talks. I presented
a handy utility called exuberant ctags for indexing source code and showed
how nicely it plays with Ruby and Vim. Here's a recap of my 5 minute lightning
talk (along with a few points I failed to mention).

Setup:
# From the top level of your project
ctags --recurse

Once it finishes there will be a file called 'tags' in your working directory.
In my case vim loads tag files automatically if it finds them in the same
directory from which it was launched. If for some reason your version does not
do this for Ruby files you can type the following in command mode:

set tags=[path to your tags file]

To make the change permanent add the following to your vimrc:

# Look for a tags file in vim's working directory.
au BufRead,BufNewFile *.rb set tags=tags

In both cases a comma separated list is accepted. This is nice if you are
working on multiple projects.

Usage:
ctags works with most real text editors though I'm only experienced with the vim
integration. Basically, once vim has loaded the tags file you can place
the cursor on top of any word and press cntrl - ] to jump to the
declaration. In some cases users will notice their terminal also has that
specific key combination bound. Under gnome-terminal I have to press cntl-shift - ] to
access my tags. In the case where more than one tag matches a selection
mode will be displayed. Usually it's fairly obvious which one you want.

Also worth mentioning is vim's tagstack. It works pretty much as expected. You push down as far as you
want and then use cntrl - t to pop back.

Limitations:

Obviously this sort of indexing faces challenges when working with a language
as dynamic as Ruby. Things that trip it up are method aliases and any fancy
metaprogramming.

ctags vs rtags

There is a Ruby ctags alternative called rtags. In my opinion ctags works better:
  1. ctags is several orders of magnitude faster that rtags. On my laptop a 100,000 SLOC project is indexed in less than one second. rtags takes about a minute to do the same.
  2. ctags supports dozens of languages. Run ctags --list-languages to see them all.
  3. rtags has trouble parsing files on most Ruby projects I work on. This is what led me to switch back to ctags in the first place.
  4. rtags claims to be more aware of Ruby syntax though in practice I find it indexes many things I just don't care about.

Saturday, March 8, 2008

GEB part two

I finished the second (and final) part of "Godel, Escher, Bach" last weekend. Originally I was thinking about all the clever things that could be said about the book but now I don't think there is much value in doing so. The one thing I can say is that this book was vital in luring me out of my mental rut of technical reading. In short, I recommend this book to everyone.

It's hard to express in words exactly why I believe this book is such an important read. Ironically, that is one of the major themes from the book. It deals greatly with holism vs. reductionism. I can see quite patently that the whole of GEB is greater than the sum of it's chapters.

Should you decide to read GEB I suggest that you read the entire work. Due to its length it's probably one of the most half-read books of our time. Many of the people that recommended the book to me said things like, "It's a great book! Though I only read the first (x) pages". Strangely enough I did meet one person who said they read the entire work in 18 hours straight.

No matter how long it takes if you stick with it you will be rewarded many times over. It took me 3 months and I confess there were indeed times in which I felt I was understanding very little. However, time after time, I would reach a point where things started weaving together in the sort of "Eternal Golden Braid" that I believe Hofstadter intended. I venture to say that, while you may indeed walk away with completely different insights about the book's "meaning", your experience will be quite similar.

<obligatory_Reading_Rainbow_quote>
"But you don't have to take my word for it..."
</obligatory_Reading_Rainbow_quote>

Tags

my google reader feed