Every time I touch Ruby - No Fluff Just Stuff

Every time I touch Ruby

Posted by: Venkat Subramaniam on September 12, 2006

A couple of years ago, when I needed email notification on a svn repository,
I wrote a C# program that will alert me on changes and provide information on
what was checked in, by whom, and the check in comment, etc. In order to gather
this information, I had to obviously call svnlook with different arguments. So, I wrote

public static string ExecSvnlook(string arguments)
{
   using(Process theProcess = new Process())
   {
      theProcess.StartInfo = new ProcessStartInfo(svnlook, arguments);
      theProcess.StartInfo.RedirectStandardOutput = true;
      theProcess.StartInfo.RedirectStandardInput = true;
      theProcess.StartInfo.RedirectStandardOutput = true;
      theProcess.StartInfo.UseShellExecute = false;

      if (theProcess.Start())
      {
         StreamReader stdOut = theProcess.StandardOutput; 
         string response = stdOut.ReadToEnd();
         return response;
      }
      else
      {
         return "error";
      }
   }
}

I had found .NET to be very productive and I still find it productive in a number of areas.
However, when I had to provide notification for another repository, I did it a bit differently
this time. I could have reused the C# code I wrote. Instead, I decided to write it this time
using Ruby (Programmers will secretively admit that rewrite is more fun than reuse :)).
The result, above method turned into:

def exec_svnlook
`svnlook #{arguments}`.chomp
end

In fact I didn't need this method. I was able to directly use the call where I needed it with a
couple of lines more to check for error.

When all was said and done (for what I wanted this notification to be), with good indentation
and spacing, .NET code was about 140 lines plus a configuration file. Ruby was a total of 50
lines with no configuration file.

More and more of my administrative scripts are turning up in Ruby. I've written code to update
database, send out automatic email notifications, doing back up and copying of files across
machines, ...

I had quite a few aha moments on the Rails project that I worked on earlier this year.
The real strength of Rail comes from Ruby. If you're still testing the Ruby waters, you may want
to take a look at Bruce Tate's "From Java to Ruby."

I had the pleasure of reading the above book and Stu and Justin's "Rails for Java Programmers."
I learned a great deal from their discussions and arguments.

As Stu and Justin put it, ?Rails is the gateway drug, Ruby is the addiction.?

I will next share how my .NET code has changed due to Ruby influence.

Venkat Subramaniam

About Venkat Subramaniam

Dr. Venkat Subramaniam is an award-winning author, founder of Agile Developer, Inc., creator of agilelearner.com, and an instructional professor at the University of Houston.

He has trained and mentored thousands of software developers in the US, Canada, Europe, and Asia, and is a regularly-invited speaker at several international conferences. Venkat helps his clients effectively apply and succeed with sustainable agile practices on their software projects.

Venkat is a (co)author of multiple technical books, including the 2007 Jolt Productivity award winning book Practices of an Agile Developer. You can find a list of his books at agiledeveloper.com. You can reach him by email at venkats@agiledeveloper.com or on twitter at @venkat_s.

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »