The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Lost in time, lost in space

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Piergiuliano Bossi

Posts: 92
Nickname: thebox
Registered: Jan, 2004

Piergiuliano Bossi is an XP coach & programmer & curious mind since a lot of time
Lost in time, lost in space Posted: Jan 9, 2006 4:07 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by Piergiuliano Bossi.
Original Post: Lost in time, lost in space
Feed Title: theboxx
Feed URL: http://docs.codehaus.org/dashboard.action
Feed Description: Ideas, thoughts, feedback, rants and some noise about XP, agile, ruby, Fitnesse, etc.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Piergiuliano Bossi
Latest Posts From theboxx

Advertisement

Yesterday I've forgotten to add one important point to my post about "Everyday ruby": after developing the script under Windows with ruby 1.8.2 I recognized I could have put it in crontab on a linux server, where several metrics are already gained or calculated every night. When I tried I had a bad surprise: our old linux server was running debian woody, an old stable release dated 2002, on which only ruby 1.6.7 is available. Hence, some of the libraries that I used where not available. For example, I have used new FileUtils module. After 5 seconds of panic I've thought that the script could easily recognize which ruby version is running, deciding to redefine a few methods for backward compatibility. It took me 10 minutes to understand what I was missing and write the following:


def is_old_ruby?
VERSION < "1.8.0"
end

require is_old_ruby? ? 'ftools' : 'fileutils'

if is_old_ruby?
def pwd
Dir.pwd
end
def mkdir_p(path)
Dir.mkdir(path) if !File.exist? path
end
def cd(path)
Dir.chdir(path)
end
else
include FileUtils::Verbose
end

Ugly, but it saved my day.

It took me some more minutes to understand that I needed to invoke shell commands or external programs differently between Windows and linux. Therefore, with a little help from the following method, I've simply modified a few invocations accordingly:


def is_win?
is_old_ruby? ? PLATFORM =~ "mswin" : PLATFORM.match("mswin")
end

I know I could have done it the same way with other languages, but believe me when I tell you that backward compatibility with statically typed language is a lot more harded, even in the simplest case like this one.

This is another good reason why choosing ruby for your everyday tasks at the border of your programming environment may be a good idea. Even when java pays the bills.

Read: Lost in time, lost in space

Topic: Dual core laptops are imminent, Apple and otherwise Previous Topic   Next Topic Topic: Oooh, I'm afraid now!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use