Re: when will Tuple be std?
- From: Jan Burse <janburse@xxxxxxxxxxx>
- Date: Fri, 28 Dec 2007 16:44:48 +0100
Stefan Ram schrieb:
apm35@xxxxxxxxxxxxxxxxxx writes:I have found the project, http://javatuple.com/index.shtml, which is
useful and encouraging, but I wonder how long it will be before Tuple
is std. The fact that this project exists shows I am not the only one
that wants to see a Tuple class in java.
»Java was actually designed to have tuples from the start,
but they never quite got in.«
http://gbracha.blogspot.com/2007/02/tuples.html
"I totally agree with the need for tuples. The
problem of "multiple return values" is indeed
a pain."
Yes if you cultivate a functional programming style.
But you can adapt the beans programming style, which
can be handy to return multiple values. So instead
of heading a function (which works in Java only
for m<=1):
Declaration:
public class Module
public static return1 ... returnm fun(arg1,..,argn) {
}
Use:
x1,..,xm = fun(a1,..,an)
You could do the following. Namely create an object
for an invokation, and populate it before the invokation,
and read the values after the invokation:
Declaration
public class Bean
public void setArg1(arg1);
...
public void setArgn(argn);
public return1 getReturn1();
...
public returnm getReturnm();
public void fun() {
}
Use:
Bean bean=new Bean();
bean.setArg1(a1);
...
bean.setArg1(a1);
bean.fun();
x1 = bean.getReturn1();
...
xm = bean.getReturnm();
There are some pros and cons to the bean approach.
Namely:
pros: Reentrant, as long as you follow the rule
one thread per bean.
pros: Default values possible, you can recognize
when a setter is not called.
pros: Optimizations possible when arguments are
provided, for example some arguments can be
provided before a looping call of fun, and
some can be provided inside the loop.
cons: Less readable code, need to track very
carefully when which argument is passed.
pros: Can even define familiy of releated functions,
with related arguments and returns.
cons: Even less readable code, when multiple
related functions are provided, and when side
effects are not clear from the outside of the bean.
I first saw this "pattern" here:
Java Modeling in Color with UML,
Coad, Lefebvre, De Luca, 1999
They use the color pink/the stereotype moment-interval
for classes that are such functional beans. And they
even aggregate such beans.
Best Regards
.
- References:
- when will Tuple be std?
- From: apm35
- when will Tuple be std?
- Prev by Date: Re: How To retrieve the full user name, in Vista??
- Next by Date: Re: question about the toString Method
- Previous by thread: Re: when will Tuple be std?
- Next by thread: Re: when will Tuple be std?
- Index(es):
Relevant Pages
|