News for hackers. Stuff that matters.
Re:Java is becoming the new Cobol by aston on Saturday December 29, 2007 @03:51AM (#93439)
A good contrast to make between Java and other languages on over-typing is Java's lack of a way to return multiple items at a time without making a container class.
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?
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_values
Re:Java is becoming the new Cobol by Tichy on Saturday December 29, 2007 @05:23PM (#93538)
That'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.
Re:Java is becoming the new Cobol by aston on Saturday December 29, 2007 @05:57PM (#93541)
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.
Re:Java is becoming the new Cobol by Tichy on Saturday December 29, 2007 @06:15PM (#93544)
Agreed, the inflexible arrays are quite annoying, maybe THE most annoying aspect of Java.