Friday, November 28, 2008

R for Ruby, R for Restless, R for Remodelling, R for Ridiculous!

Oh Well, I had never been interviewed by software major Google but I read in some blogs that they ask for the candidates favorite equation. My favorite equation is that of a rectangular hyperbola xy = c^2 (Read C squared)

Because this explains life. As you see, this is the equation of trade-offs. And pals, what is life ? Isn't is a conglomerate of several trade-offs?

Well, take newly popping up programming languages for example, Ruby. The creator of this language claims that it is "Beautiful", because it is script like (Almost a close cousin of MATLAB).
MATLAB and Ruby scripts both lack the details about the variables involved in the code, which makes it reasonably and arguably difficult to debug.

People say, Examples are better taught. Let me try!

C/C++/C#/Java
-------------------
int x = 10;

Ruby/MATLAB
--------------
x = {}

In the first declaration, the programmer will know right away that x is nothing but an innocent integer which is initialized with a "Ronaldinho Gaucho's Jersey No" or my "Grandpa's Shoesize" or something that can take up the value 10.

But, dear Ruby coders, the second statement can mean anything. x can be a simple array, can be a hash table, can be a string. Unless we use it, you will not know our intention.

It is like, I give you a box and ask you to wait like "Pandora" until late. Then you know....
Abstraction is good as far as the users can make out what is the interface. Nothing more is judicial.


Other bad feature is everything in Ruby is an object. For example
5.days.from.now

type of code is possible in that language. Which is Ridiculous and Redundant. Because a simple age old function like

DateTime AddDays(int)

would do the trick.

These features will only make the code more unreadable.

So brevity is not always synonymous with beautiful. These are the basic reasons I don't use Ruby or that kind of cryptic (Yes you read it right) languages.

2 comments:

nathan.f77 said...

Hello, I'm here to argue :)

Firstly, you don't seem to fully understand the beauty of untyped variables. I agree, 'duck-typing' is a difficult concept to grasp for traditionalists such as yourself, but in my 8 months with Ruby, my productivity has increased 10-fold.
In my experience, I have had little to no unintentional bugs directly caused by untyped variables. Rather, I have extremely enjoyed the freedom. Consider the following short program:

def some_method(arg1)
arg1 ? "x" * 5 : false
end

if some_method(true)
5.times do |i|
print i
end
end

Let me explain it.

We define a method that uses a ternary operator (the ? : bit) that can either return false, or a string, depending on the value of arg1.
(Note that "x" * 5 in ruby is "xxxxx", and methods dont need an explicit return).

The 'if' statement checks the result of our method. If the result is boolean false, or nil, then the 'if' block would be skipped. But our example method returns "xxxxx", and any string, integer, floating point, array, hash, or range is considered as true to an 'if' statement. The 'if' block then prints "12345" to the screen.

The whole 'if' block can be turned into one line if you want:

5.times {|i| p i} if some_method(true)

And printing the numbers from 1 to 100 is as simple as:

(1..100).each {|i| puts i}

I could go on.

Sorry if some of the code was hard for you to understand, but don't use that as an argument. Its like me saying "I don't find FORTRAN readable" when I have never even tried to learn it.

I know C, and use it very regularly with my device driver work. I coded in .NET for 4 years, and consider Ruby to be the most beautiful language I have ever developed in.

Finally, in what way does "5.days.from.now" make the code unreadable? That is the most readable code I have ever seen!

I enjoy Ruby very much, and your post was just waiting for someone to argue their point :)


Nathan B

Ariel Rosado said...

So you made a blog just for such a crappy and emotional, fact less post?

U suck!