Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Can you perhaps suggest a better pair of Java and Ruby programs that would serve as a counterexample?


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.


How do other languages do it? I can't actually imagine it, odd as it sounds? You don't mean returning maps, I presume?


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?)


If you indent something a little,

 it will look like this
 as you would expect from
 a <pre> tag


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


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.


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.


Agreed, the inflexible arrays are quite annoying, maybe THE most annoying aspect of Java.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: