Re: when will Tuple be std?



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
.



Relevant Pages

  • Re: .a developer must create an ejbHome
    ... I think you're confusing the content in the EJB Bean class, ... it's ejb... ... @return Returns the age. ... public void setName{ ...
    (comp.lang.java.programmer)
  • J2EE + Beans advice required
    ... create multiple instances of a bean, ... private String name; ... public void ejbCreate ... public void ejbRemovethrows RemoteException, ...
    (comp.lang.java.programmer)
  • Client cannot locate Container-Managed Entity Bean Sun Applicaton Server Nine
    ... I cannot find my Course J2EE bean from a client. ... public void setName throws RemoteException; ... public void setNumber (int n) throws RemoteException; ...
    (comp.lang.java.programmer)
  • Re: converting code into a bean
    ... > a set method for them. ... be changed anytime the bean is droppen onto a form (ie design time only - ... public void setInit{ ... there is a value int he property sheet valled "value" which is ...
    (comp.lang.java.programmer)
  • Re: [jsp]: getProperty
    ... public void setVectorName{ ... so it should take that int value, send it to a method in another class and ... that then gets saved in my bean. ... Marcus ...
    (comp.lang.java.programmer)