[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: Need examples comparing Ruby to Python
From: Hal Fulton <hal9000 () hypermetrics ! com>
Date: 2004-02-24 20:06:02
Message-ID: 403BAEA4.5090209 () hypermetrics ! com
[Download RAW message or body]
David MacQuigg wrote:
> I'm not seeing any fundamental advantage of Ruby blocks over Python
> functions. If your block is more than one line, or needs a print
> statement, just give it a name and let it be a function. lambda's are
> used only for very short blocks, where for example, you want to pass a
> simple function in an argument list, but don't want to waste a line
> giving that function a name.
David,
The *last* thing I want is to start a flame war, especially since my
knowledge of Python is practically zero.
But I had to laugh at that statement -- "if your block is more than
one line, or needs a print statement, just give it a name and let it
be a function."
I'm not saying that your arguments are ridiculous or laughable -- I'm
just saying there is obviously some very fundamental disconnect between
your thinking and mine. I'd like to discover the nature of that
disconnect.
Here is a simple example of a block that is both multi-line and has a
print statement. (Granted it could be done in one line.)
words.each do |word|
consonants = word.gsub(/[aeiou]/,"")
puts consonants
end
How would you do that with a named function, and why would the new way
be better?
If I do:
def func(word)
consonants = word.gsub(/[aeiou]/,"")
puts consonants
end
words.each {|word| func(word) }
then I have still used a block, one that happens to call a function
(with a name) that will only be used once.
Is this better than the other way?
Thanks,
Hal
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic