commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Cooper" <martin.coo...@tumbleweed.com>
Subject RE: [lang] Ideas for Lang
Date Mon, 14 Oct 2002 18:18:32 GMT


> -----Original Message-----
> From: Henri Yandell [mailto:bayard@generationjava.com]
> Sent: Monday, October 14, 2002 5:33 AM
> To: Jakarta Commons Developers List
> Subject: Re: [lang] Ideas for Lang
> 
> 
> 
> On Mon, 14 Oct 2002, John Yu wrote:
> 
> > > >  > 4) Pair. Is this Collections? Dunno. Anyway, pairs 
> seem to be nice
> > > >  > sometimes. I only have one because I was porting the 
> lisp examples
> > > to Java
> > > >  > from the lisp book [yep, i'm that sick].
> > > >
> > > > Isn't o.a.c.collections.DefaultMapEntry, fulfilling the 
> role of Pair?
> > >
> > >Possibly, though it isn't semantically. Assuming there's a 
> need for a Pair
> > >class, using DefaultMapEntry would not fulfill it, even if the
> > >functionality were the same.
> > >
> > >My vague view being that things can be syntactically the same but
> > >semantically different.
> >
> >
> > You lost me.
> > Could you elaborate? What semantics you're referring to in Pair?
> 
> Erm.. pass? :)
> 
> I was hoping there might be a good Lisp fanatic or something with some
> reasons for why a Pair object would be very useful. I seem to recall
> reading someone's blog opining for a Pair class.

Well, you could certainly do lists the LISP way with a Pair class. One
element is the CAR and the other is the CDR. Then you could build the other
list operations on top of it quite simply. That's not to say this is a good
idea, but you *could*. ;-)

> 
> The semantic bit was... I think there are many places where 
> someone would
> like to use a Pair and not a DefaultMapEntry. ie) They're not 
> dealing with
> Map.Entry functionality.

I agree with this. The cases where I've wanted a Pair class have not been
related to maps, and I think it would be confusing to (a) imply that a pair
is related to a map, and (b) have fields named 'key' and 'value'.

Of course, this begs the question of what *do* you call the elements of a
generic Pair class, to avoid implying any semantic. I guess you can't really
go far beyond 'obj1' and 'obj2'.

> 
> [One of the dangerous parts of suggesting ideas you don't 
> believe in a lot
> yourself :) ] Similar for the Mutable-primitives. I often 
> find a point in
> code where I think, "wish I could set the Integer", but then 
> I get around
> it somehow without much effort.

The Mutable idea would solve the case where you need to return more than one
value from a method. One icky way of doing that is to pass an array into the
method, and have the method set the entry/entries in the array. Using a
Mutable object would at least avoid the need for the array.

Of course, maybe you could just return a Pair instead... ;-)

--
Martin Cooper


> 
> Hen
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: 
> <mailto:commons-dev-help@jakarta.apache.org>
> 
> 


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message