Bear Bibeault wrote:Messy! I'd go with abstracting the values into a class or interface.
I left Mike the right to choose between both approaches
And I appreciate it, so long as the method is easy to enact and understand I don't see the problem. It seems to me that Java itself is rather poor in not allowing the return of multiple values from a method. There are many ways to skin a cat, some prettier than others, but so long as you understand how it's done it doesn't mater which way you choose.
I know the method.get() exists and works (and I use it in other areas), I was looking for other ways to do it, and Christophe showed another possibility. Thanks.
I can't name one single programming language that has multiple return types. Python appears to have this feature but in fact it doesn't - it uses a combination of returning a tuple and splitting (is this called slicing as well?). For instance, the following Python code creates a tuple variable around two variables, then assigns the returned tuple to this tuple, then dissolved the tuple again:
This is actually the same as this:
So no, no multiple return there.
Joined: Sep 11, 2007
Rob Prime wrote:I can't name one single programming language that has multiple return types.
Just because you don't know them doesn't mean they don't exist.
Rugby's the same way. (That'd be Ruby; thanks Droid autocomplete.)
Re the litany of dead/dying languages: maybe there's a reason that more recent ones haven't followed suit? It's just not something found in most OO languages, since there are ways to deal with it. Java makes it a bit more troublesome than some, but the drawbacks of making ad-hoc data structures are the same as they've always been.
Joined: Sep 11, 2007
David Newton wrote:Re the litany of dead/dying languages: maybe there's a reason that more recent ones haven't followed suit?
I've heard that diatribe since the 80's, in the mid- large- business world they are still going strong. I've done consulting at a number of companies that are giving up SQL-based servers because of their poor speed when compared to mainframes. Oracle has released a MF version of its' DB with Cobol interfaces. IBM now has a mainframe capable of GUI interfaces via Cobol, and the next release of the language will follow suit. Having been in the business since the 60's I've seen MF and PC based languages come and go; at this point there is no clear winner in the PC arena (Java is just another player in the field) and none is as widely used as Cobol.
Rob Prime wrote:I can't name one single programming language that has multiple return types. Python appears to have this feature but in fact it doesn't - it uses a combination of returning a tuple and splitting (is this called slicing as well?).
I'm not sure I understand the distinction being made here. It seems to me that Python does allow the programmer to return multiple values from a function, and the tuple is the underlying mechanism that allows this to happen. In that sense, I would say that Perl, Python, Ruby, Groovy, Scala, and C# all allow returning multiple values. Scala and C# even do it while preserving static typing of each element. Am missing something? Is returning a tuple significantly different from returning multiple values?
this is typically the field of dynamic typed languages where there is no static typing and returning by map style is common and straightforward.
for exampl in groovy i would not hesitate to do:
in java on the other hand i would never return a Map<String,Object>. Java is static typed so I wouldn't try to bypass the static typed information by using Object for all variables and casting around later (apart from some reflection magic, which is sometimes necessary).
For Java I would create a dedicated custom return class: