my2cents

7. April, 2007

Learning Ruby

Filed under: Ruby — frightanic @ 11:11

For various reasons my wife and I decided to stay home this Easter. This gives her time to prepare an upcoming business meeting in Tokyo and I, well, I decided to step into the Ruby swamp this weekend. Dave Thomas’ “Programming Ruby” has been laying around for some months now, but I never really get around to dig into it.

I’ve made it through the first few chapters of the book. Ruby is installed on my MacBook (it came preconfigured) and on my Windows 2000 PC, I installed the RDT plugin for both Eclipse installations and wrote my first Ruby classes.

I’m still waiting to be impressed.

I never liked cryptic programming languages – that’s why I never learned Perl. And that’s probabely the reason why I still like the verbosity of Java after so many years. I like expressive grammar/APIs because I’ve been working with good IDEs all the time. If I didn’t have code completion and code templates things would probably be different. I’m not at all more productive just because I have to write fewer characters to achieve the same functionality.
Don’t get me wrong, I’m not (yet?) ranting about Ruby. So far, its grammar is simply not appealing to me and I know too little about the language to judge whether its claimed advantages over other languages will offset this.

  • It’s nice to inject something into a string with "Hello #theNameVariable" instead of writing "Hello " + theNameVariable but I prefer the expressive version.
  • What’s the point in syntactically separating instance variables @name from class variables (static variables in Java) @@name? The source code will become cluttered up with special characters – yuck.
  • Attributes are prefixed with a ‘:’. See above…
  • Why would I want to name a method that converts the state of an object into a string to_s instead of toString? What do I gain?
  • I’m not yet sure whether I like the implicit “getter/setter” methods for attributs. Ok, I have to write or generate (as modern IDEs do) less code, but the expressiveness of my code suffers from that.
  • On the other hand it’s nice to have virtual attributes. The Uniformed Access Principle as put forth by Bertrand Meyer has made it into Ruby.

To be continued…

Advertisements

Create a free website or blog at WordPress.com.

%d bloggers like this: