Re:Java is becoming the new Cobol
by Tichy on Saturday December 29, 2007 @03:54AM
(#93441)
How do other languages do it? I can't actually imagine it, odd as it sounds? You don't mean returning maps, I presume?
[ Parent
| on HN ]
Re:Java is becoming the new Cobol
by Xichekolas on Saturday December 29, 2007 @06:53AM
(#93458)
def return_three_values
"1,2,3".split(',')
end
a, b, c = return_three_values
Like that?
(For the love of god, how do I get that in a pre tag?)
Re:Java is becoming the new Cobol
by bayareaguy on Saturday December 29, 2007 @07:20AM
(#93460)
If you indent something a little,
it will look like this
as you would expect from
a <pre> tag
Re:Java is becoming the new Cobol
by Xichekolas on Saturday December 29, 2007 @03:04PM
(#93521)
Ahhh, I tried that, but apparently it doesn't work if you do it on the first line. So here it is, not on the first line.
def return_three_values
"1,2,3".split(',')
end
a, b, c = return_three_valuesThat's just returning an array, though, which Java could also do. What Java can't do is to assign variables to array values as in your example.
So, yes, the lack of assignment is part of the problem. But, of course, the duck-typing is half the fun of something like that. I can return anything (of any type) I want in a tuple of any size just by comma delimiting. Java arrays aren't that flexible, and worse, if you use one that holds more than one type (say Integers and Floats), you have to cast them to Object before you drop them in, and you get to cast on the way back out. Lots of type-related overhead to simulate something that should be easy.