Re:What's better about Ruby than Python? - comp.lang.python
by spicyj on Thursday August 26, 2010 @08:47PM
(#1637682)
Or a slightly more direct translation is:
result = if baz > 10
foo
else
bar
end
Re:What's better about Ruby than Python? - comp.lang.python
by Dylan16807 on Friday August 27, 2010 @02:39PM
(#1639710)
result = case
when baz>10 then foo
else bar
end
is a translation of if baz>10:
result = self.foo()
else:
result = self.bar()
while result = if baz > 10
foo
else
bar
end
is a translation of result = self.foo() if baz>10 else self.bar()
It's true that some things have to be changed when translating, but you can't ignore the deliberate structure of the original. Let's say I want to look at how inter-sentence objects work in two languages. I give you the phrase: "Raining cats and dogs. This is what the weather is like." You can't translate it as if it said "It's raining cats and dogs" without losing the basis of comparison entirely.
So, for instance, you might solve it with:
This is synthetic, of course. If the goal is to pass around methods, there are lambdas and codeblocks that can be passed around and may fit the problem more naturally than sending yourself a symbol as a message.