WatTF? – Jim Murphy

{It’s Safer to be Risky}

WatTF? – Jim Murphy header image 2

Ruby Smells

February 29th, 2008 · 3 Comments

So I’ve had a low priority background thread spun up for a year or so learning Ruby and more importantly for me Rails. Some of the guys at Mindreef have ported our Struts/Spring/Hibernate web app front end to Groovy + Grails so I’ve been watching that go pretty well. For a Java guy thast a pretty compelling way to go. But, nonethless I’m spending time with the Ruby Language in parallel.

I really like Rails/ActiveRecord/Scaffold – I think thats a significant innovation over the swamp that is XML configuration in Java. I’m going to keep learning Ruby but I constantly find syntax weirdnesses that make do a double take. Here’s a list of my ‘Ruby Smells’ that I’ll add to asI go:

1. Conditionals – anything other than false and nil is true

1 if (0)
2    puts "zero is true"

2. Equality – How many ways can you say it and quick what does each mean?

1 o.eql
2 ==
3 ===
4 o.equals

Quick now, quick!

3. Tease me with curlies.

1 def foo
2    puts "This method definition would look better with curly braces, end makes me feel like a VB programmer.  Not that there's anything wrong with that."
3 end

Like:

1 def foo
2 {
3   puts "this would be better"
4 }

My brain is wired to use curly braces to guide my eyes when reading code, especially someone else’s code. I realize its not necessary or transparent so this is an area I will adjust but, then to see them liberally sprinkled everywhere else seems like a complete tease (blocks, Hash defs etc.).

4.@ Notation for instance fields and @@ on class fields and the $?

1 class cat
2   @wiskers=4
3   @@feet=4
4 end

A syntax only a mother could love. Syntax inspiration from Perl and PHP – not a good choice, IMHO.

Hopefully I’ll add more substantive Ruby Smells over time. Feel free to send me yours.

Bookmark and Share

Tags: Uncategorized

Comments
  1. Aaron White posted the following on February 29, 2008 at 10:58 am.

    Ya, the ruby syntax is god awful. I feel like i’m looking at bash spew. If you’re interested, I can share my ‘uber-stack’ for Java for comparison: Hibernate w/ Annotations + Guice + Stripes/Stripernate. Really really great!

  2. Jeff Fedor posted the following on March 1, 2008 at 9:05 pm.

    smells +1 but anything that looks different than objective C seems so foreign to me :-p

  3. Jim Murphy posted the following on March 10, 2008 at 3:32 pm.

    Gotta think up some more of these but, the time…the time!


Leave a reply

Click here to close

Add a Comment