Our First Code Day!


By Greg Houston


Our first Rubyham Code Day was a great success. Since this was our very first event of this kind I wasn’t expecting much from it. Going into the event, I told Josh that I would be surprised if we got any coding done. However, by the end of our scheduled time we had a working system!


The event started last Saturday at 9am. Josh had acquired space at Isotope Eleven’s offices for our meeting. Immediately we hit our first problem. The security guard at the building decided it was a good day to stay home. So we didn’t have a key to the office. After trying in vain to get the keys quickly, we punted and moved the meeting to Coffee on Valley (http://www.coffeeonvalley.com). At that time, four people had shown up: Josh, Kevin, Doug (from Montgomery), and myself.


Coffee on Valley turned out to be a perfect place for our meeting. The shop had plenty of tables, food, and great coffee. Their free wifi service worked flawlessly. We choose to sit around a big conference table in one of their side rooms. Next time we will have to reserve their room with the big screen monitor. (Sorry, I forgot to bring my camera). One side of the table had PC users and the other Apples. We didn’t plan it that way, it just happened.


Surrounded by “atmosphere” Kevin, Doug and I got settled into writing the xml diff engine. None of us really had much of a plan. We just started writing unit tests and working through the problem test-first. The method we used was similar to pair programming, except the three of use gathered around a single Mac. Josh wrote the Rails code, which was simple as dirt. Since it didn’t take Josh long, he worked on some of his other projects. Seth showed up mid-morning and followed along with Josh and his amazing vim skills.


We used Assembla (http://assembla.com) to host the project. The svn repository is located at: http://tools.assembla.com/svn/xml_diff/ which requires an Assembla login to access. Here is an example test…


require 'rexml/document'
require 'rexml/xpath'

module XMLDiff
  class XMLDiff
    def self.Diff( left, right)
      result = REXML::Document.new( "<xmldiff />")
      Walk( left ) { |e|
        e_found = REXML::XPath.first( right, e.xpath)
        unless e_found
          result.root.add_element( 'element', { 'diff' => 'left', 'path' => e.xpath } )
          left_text = e.text
          if left_text != e_found.text
            el = result.root.add_element( 'element', { 'diff' => 'diff', 'path' => e.xpath } )
            el.add_element('left', {}).add_text(left_text)
            el.add_element('right', {}).add_text(e_found.text)
          if e.attributes != e_found.attributes
            el = result.root.add_element( 'element', { 'diff' => 'diff_attr', 'path' => e.xpath } )
            el.add_element('left', {}).add_text(e.attributes.collect{|a,value| "#{a}=#{value}"}.join(','))
            el.add_element('right', {}).add_text(e_found.attributes.collect{|a,value| "#{a}=#{value}"}.join(','))


        Walk( right )  { |e|
           e_found = REXML::XPath.first( left, e.xpath)
           unless e_found
             result.root.add_element( 'element', { 'diff' => 'right', 'path' => e.xpath } )
      return( result )

    def self.Walk( element, &block )
      element.each_element { |e|
        yield e
        Walk( e, &block )



At the end of the morning, we had a great understanding of the REXML library and the problem domain. We discussed changing our approach and output format, but didn’t have the time to try it. The code above performs a top-down walk of the XML tree. Instead we think a bottom-up approach is better since we could roll-up results to parent nodes. Also, instead of comparing individual elements, we realized that we should have looked at the set of elements available at each level.


As we wrapped up coding, everyone did a little “show-and-tell” of projects they developing. Josh showed off his Rails based content management system. Kevin showed his Active Record prowess by explaining how to get active record to join and return from 9 tables in one call! I was really impressed by this because instead of having a couple pages of SQL, he only needed 3 lines of Ruby! Maybe Kevin can blog about it soon.


As we parted, Seth took away the door prize: Rails Cookbook (great book: http://www.oreilly.com/catalog/9780596527310/). Everyone had great fun. Hopefully we can have the next code day soon. Until then, Atlrug is holding a code day on Feb 17th (http://ruby.meetup.com/83/).


No Responses Yet to “Our First Code Day!”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: