02 May 2006

Ruby. Syntax. Taste

Oh, Ruby has become a hot topic on KDE blogs again :) Let me also join with my 2 kopiykas.

My taste of programming languages tells me Python is not good for me. I don't want to claim here Python is bad, it's just not the language of my choice.

There are two good things about Ruby. First - when I've started learning both Python and Ruby year ago Ruby was perceived "cool". Today I work on Ruby (and Rails) projects half-time and the language is still "cool". There's nothing like this feeling to be commited to something cool :) Good advertising you say. Yep, pretty good but there's also something inside me telling Ruby is cool ;) Cornelius described that feeling in a more precise way.

The second good thing I found about Ruby is syntax. Surprise! Looking at the blogs and comments most people complain about perlish syntax. It's probably possible to write perlish code in Ruby but I barely see anyone does it. For example, what's wrong with Richard Dale's code?

Honestly, syntax matters were the first to take my attention away from Python. I like def initialize more than def __init__(self):. I also like code blocks ending with end and not just backward indentation. Writing self.foo disturbs me more than @foo. My list of preferences is long :)

Ok, I'm sure Python is a great language but I like Ruby more!

11 comments:

Alexander Dymo said...

Thomas, I'm not really participating in the "language for Visual Basic programmers". You're right, I'm not the one to decide on this question. Just wanted to say that Ruby syntax is not that bad as people depict in their blogs;)

Anonymous said...

As much I like the ruby language itself, I dislike the method naming for built-in classes like String:

Method names such as "sub", "gsub!", "eql?", "to_i", (which are often used methods, my personal favorite is "issjis", but that's admittedly rare) just make me scratch my head.
Or in Array:
"to_ary" instead of "to_array", uniq! for removing duplicates...

Maybe it's my Qt/C++ and Java background, but I prefer more readable method names, like "replace", "equals", "toInt".

Anonymous said...

> self.foo disturbs me more than @foo

Both is disturbing. Referencing self to access variables from inside of a class should not be necessary, but implicitly given.

Anonymous said...

You know, I have already solved the python indentation problem ;-)

http://cablemodem.fibertel.com.ar/lateral/weblog/2006/04/02.html#P347

Alexander Dymo said...

>> self.foo disturbs me more than @foo
>Both is disturbing.
Yeah, that's why I say one disturbs me more than another :)

> You know, I have already solved the python > indentation problem ;-)
Hey, that's cool. I'll show it to python addicts from my university! They would love it :)

Anonymous said...

I like how wceryone uses vb as their basis for comparison. When will they do that to python. I tried python almost 2 years back and gave it the same effort that I gave ruby last year. Ruby won hands down.

Unknown said...

Ruby code is still uglier, perlish, inconsistent and harder to read than Python code, no matter how you slice it. :-P

I knew something was wrong when when I couldn't differentiate between a statement and method in Ruby (WTF?). Then all those irritating nested "ends" that serve no purpose other than to distract and waste space. And then we have the redundant symbols and syntax. Ruby like Perl is write only language.

Anonymous said...

It sems some poeple here are easily disturbed. I'll not pretend that Python's handling of variable scope is perfect, but in practice I find it unproblematic and the self.var syntax is at least clear. Both languages have some odd idiosyncrasies - few languages don't - but these are realy trivial points. I just think it's sad anyone feels thay have to choose camps.

What we realy need is a common scripting platform that makes choice of language a non-issue. Perhaps Parrot will give us that, perhaps Mono or the JVM through projects like Jython and Iron Python. On Windows it's already accademic for most purposes through COM interop.

Anonymous said...

Regarding the self.foo vs. @foo issue : it's perfectly normal and very wide-spread to distinguish the use of a member variable as opposed to a local one. Why do you think most C++ or Java code convention feature the use of a prefix like 'mFoo' or '_foo' for member variables ? It makes code much more readable.

IMHO this is one thing (among many) which Ruby got right, using typographic conventions to denote the scope of the variables (local, member, class, global) rather than their type (scalar or array, like in Perl), because it just reproduces what you will do in any OO language anyway, with the added benefit that the language actually understands these conventions in this case. Python's 'self' is just embarassing in comparison.

However Python's ridig syntax does have the advantage that Python code is generally more maintainable than Ruby, especially when working on a shared code base, because pretty much everybody is forced to the same style, which is hardly the case in Ruby.

Anonymous said...

Ruby's already won, at least when compared to python and perl. Python's on its way down, although some larger organizations are recently adopting it (they are always behind the curve on things like this).
There's only so many times people can put up with python's nonsensical syntax decisions (__ @ self self self) and non-actions and FUD. YES, OOP is tacked on in Python. YES, python is slow (as is ruby, compared to statically typed languages). NO, python is not beginner friendly as they would have you believe. You get nothing but BS from python fanatics.

Anonymous said...

Well, I don't think one language will replace another, whether ruby or python etc etc etc. What you seem to forget, is these open source scripting languages are really a minority pursuit, used in the main by hobbyists and the ever decreasing linux/unix tech crowd. Business tends to go for Java/.Net, etc al.
The open source stuff will float around for ages, probably for ever.
Personally I do prefer Python, over Ruby's weird syntax, and ridiculous syntactic shortcuts. However I did find Python difficult to learn, and it has ponderous code.
I'll wait for a strongly typed language like Java, that someone's written with an eye to usability.