ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Why Ruby is so great and why I'll pass and wait for the next big thing..

(1/2) > >>

mouser:
Scott Hanselman writes good stuff on programming but his article today on what's so great about Ruby is good reading for people like me looking for an excuse to give Ruby a pass.  I consider these examples to be shiboleths and i find myself squarly in the camp of those who find the "Ruby Way" to be the wrong way.

A user named yesthatmcgurk left a comment on DotNetKicks where he/she said:

I must be a complete loser, because I can't see where Ruby is such hot shit. I'd love to read a story, "What you're not getting about Ruby and why its the tits."

Such a great comment that I had to get involved. One of the other commenters pointed to a post over on "Softies on Rails" that's really worth reading.

Note: Forgive the use of "the tits" in this context. "Slang Definition: A description of something you show great liking to, or greatly appreciate..." Usually not a work-friendly phrase, but perhaps pub-appropriate.

There's a simple snippet of Ruby code:


--- Code: Ruby ---def shutter_clickedif @camera.off? || @camera.memory_card_full?  returnend  capture_imageend
Ruby folks have their own aesthetic and sense of beauty. They would say that the Programmer's Intent is better expressed like this:


--- Code: Ruby ---def shutter_clicked  capture_image if @camera.on? && @camera.memory_available?end
These two functions identically express the Programmer's Intent and the second one expresses it better, many believe.

--- End quote ---

Guess what, i don't think the second one is better, to me it's just one more example of the perl approach that the shorter the code the better the code.  I don't believe that.  I believe clarity is often best served by writing longer blocks (and good comments).  Whenever someone shows me these kinds of statements i always show them how easy it is to properly comment/debug the longer example and not the short one.
e.g.

--- Code: Ruby ---def shutter_clickedif @camera.off? || @camera.memory_card_full?  // the camera either got turned off by mistake or is full  // TODO: write error handling and detect which problem  // for now let's just return without an error.  returnend  // ok, camera is ready so let's capture the image  // TODO: make sure to reset camera state later  capture_imageend

Here's another:

There are some fun one-liner comparisons though and some folks think that paying a:
Java: 
--- Code: Java ---new Date(new Date().getTime() - 20 * 60 * 1000)Ruby:
--- Code: Ruby ---20.minutes.ago
In this example, the elegance is a combination of how Ruby works, and a Rails library called ActiveSupport that is a Domain Specific Language that extends Ruby. There's a special satisfaction when you read a well-written novel and you go over a turn of phrase and think, "wow, what a great way to express that. That was a perfect way to describe ____," and there's no ambiguity.
--- End quote ---

This reminds me of everything that's wrong with (the often exceptional) boost libraries for C++, a love of abusing syntax and using "domain-specific" additions to the language.  Again the attraction seems to be to poetic tiny little segments of code.  If you are trying to write a 5-line haiku in code, fine.  But my experience is that when you start working on larger projects, you're better of knowing when you are calling a function or accessing a variable, and not introducing operator overloading and other fancy domain language extensions, etc.

Now of course this is just a minor part of Ruby, there are other things I don't like, and other things I do like, but Ruby, like most languages, seems to have developed a strong culture of style behind it that i don't fit into, so i'll keep looking.. Just my 2 cents.

Gothi[c]:
Great post!

I'm afriad I'm in the same camp, and I agree 100%,...
I actually bit through the apple and spent a week exploring ruby and rails, by the end of it, the syntax was driving me crazy. I think they want code to look like plain English, but code doesn't look like plain English for a reason. Eventually, I told myself 'never again. Ruby isn't for me'.

app103:
Great post!

I'm afriad I'm in the same camp, and I agree 100%,...
I actually bit through the apple and spent a week exploring ruby and rails, by the end of it, the syntax was driving me crazy. I think they want code to look like plain English, but code doesn't look like plain English for a reason. Eventually, I told myself 'never again. Ruby isn't for me'.

-Gothi[c] (May 24, 2007, 03:16 AM)
--- End quote ---

If that's what they want, why aren't they programming in Plain English? ;D

Eóin:
Hey mouser, I'm not too sure I'd agree with you on the first point. Given the two bits of quoted code I would say the second one is indeed better. That's not to suggest I disagree with you regarding code comments, but I believe that's a separate issue and an improvement which could be applied to either quoted bits of code.

Although I also think the first example is purposely contrived to be bad code i.e. the multiple exit points in this case are not at all necessary.

On the topic of domain-specific additions, well I can definitely agree that in many cases people can go overboard here. But I think the Boost libraries rarely if ever do so. In example code where 'using namepsace' directives are used too liberally it can be confusing, but in larger projects those directive are usually frowned upon anyway.

I'm eager to be shown otherwise though, would you have a sample or two? :)

app103:
Coming from Delphi where I see things like this all the time:

--- Code: Delphi ---begin  Form1.Label1.Caption := 'Hello';  Form1.Label1.Font.Color := clBlue;end;
looking at something like this brings out an instinctive 'WTF?' followed by a near meltdown of my brain:

--- Code: Ruby ---20.minutes.ago
 ;D

Navigation

[0] Message Index

[#] Next page

Go to full version