View Single Post
  #5 (permalink)  
Old 08-02-2007, 01:19 AM
rpgfan3233 rpgfan3233 is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jul 2007
Posts: 118
iTrader: (0)
rpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura aboutrpgfan3233 has a spectacular aura about
There is one thing that stopped me from continuing on with Ruby. In fact, it was found in a tutorial...
Code:
def mtdarry
    10.times do |num|
        square = num * num
        return num, square if num > 5
    end
end
I understand now that it is a conditional return, but to me it would be more logical to use
Code:
if num > 5 return num, square
or whatever that would be. Honestly, I first thought of it as:
Code:
def mtdarry
    10.times do |num|
        square = num * num
        return num, square
        if num > 5
            end
end
Unfortunately, I tried that, and it didn't work since the function definition itself wasn't closed. I know that some languages don't immediately return a value when the line with return on it is executed, so that's why it made some sense. I ended up sticking with the tiny bit of Python that I know. At least that one seems more logically structured to me! For some people, that logic may work. However, I find it to be more of a nuisance for understanding the program than:
Code:
def mtdarry ():
    for num in range(0, 10):
        square = num * num
        if num > 5: return num, square
Cleaner and more logical to me, except for the lack of the iterative for loop such as for (num = 0; num < 10; num += 1) that is found in C, C++, Java, C#, various dialects of BASIC, etc.

I'm not saying that Ruby is a poor language for programming, of course. I'm simply stating that it didn't appeal to me the way that some other languages do. Because it didn't appeal to me, I warn that it may not appeal to you or some future readers. I choose Python for my own reasons, just as Ruby programmers choose Ruby for their own reasons.

__________________
"C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off."
-- Bjarne Stroustrup, creator of what is now known as C++
For more quotes by Bjarne Stroustrup, check out http://www.research.att.com/~bs/bs_faq.html#really-say-that.
Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!