Linked by Bjorn Raupach on Thu 17th Jul 2008 06:01 UTC
Java Today was one of those days when I wished Java would support multiple return values. I had to develop a rather CPU-intensive algorithm which would compute a solution for a knotty constraint problem. Having a solution alone is sometimes not enough and you also need to add some parameters which measure the quality of the computed outcome. Most of these accompanying parameters can or have to be computed within the algorithm itself, but Java allows you to return only one value either an object or a primitive type. People working with Lisp, MATLAB or Perl, just to mention a few, don't have a problem like this at all. Functions supporting multiple return values is already implemented at the language level and frameworks make heavy use of this. But as a Java programmer you are pretty much stuck here and need to consider some other means to come out of this situation. In the following I would like to give some hints on that topic. Hopefully they are of help for anyone having the same problem every now and then.
Thread beginning with comment 323462
To read all comments associated with this story, please click here.
tuples
by averycfay on Thu 17th Jul 2008 17:02 UTC
averycfay
Member since:
2005-08-29

This approach is usually generalized into tuples, which are useful in a number of situations. Examples would be:

for java: http://javatuple.com/
for c++: http://www.boost.org/doc/libs/1_35_0/libs/tuple/doc/tuple_users_gui...

RE: tuples
by FunkyELF on Thu 17th Jul 2008 17:50 in reply to "tuples"
FunkyELF Member since:
2006-07-26

That java link was nice...thanks. Once you start using tuples in other languages like Python you want to use them in everything. I looked at the code hoping it wouldn't be a big mess and it seems pretty clean. Its not a hard concept.

I didn't see a mention of a license in the download though. The site does say

You can compile the source into a jar, or make it part of your project directly.
... so it might be public domain?

EDIT: Just saw it on the bottom.... Creative Commons Attribution 3.0 United States License.

Edited 2008-07-17 17:53 UTC

Reply Parent Bookmark Score: 2