🕷 zenspider.com

by ryan davis



sitemap
Looking for the Ruby Quickref?

spelunking, pt 1

Published 2008-06-24 @ 22:13

Tagged parsetree, thoughts

I have a file containing sexps for every file in standard lib and every gem I have installed. I should extend that out and do every latest gem out there, but that’d be unbelievably large. The current file is 18M.

But… with it, I can go spelunking for interesting tidbits… For example:

  wtf = [[:args,       [15,  1]]
         [:array,      [407, 4]]
         [:block,      [274, 2]]
         [:case,       [51,  1]]
         [:dregx,      [16,  2]]
         [:dregx_once, [35,  1]]
         [:dstr,       [100, 1]]
         [:hash,       [567, 1]]]

wtf describes an interesting set of data. Each array contains a node-type, a size, and a frequency. How is this interesting? What does it mean? How about:

  • someone, somewhere, decided that 15 args were needed in a method.
  • four arrays in the code base that have 407 elements? Copy & paste anyone?
  • Two blocks (method bodies, usually) have exactly 274 nodes. Curious size, no?
  • A 51 node case statement (else + 25 whens). When was the last time you wrote 24 elsifs in a row? Were you fired for it?
  • dregx and dstr nodes are regexps and strings with interpolation… Some string out there has ONE HUNDRED nodes (usually string/#{}/string/#{}/repeat). wow

Anyhow. As I go spelunking I’ll try to come up with interesting tidbits and post them here.