Anyone ever considered named tuples?
Marek Kozieł
develop4lasu at gmail.com
Sun Mar 22 16:26:42 PDT 2009
2009/3/22 Paulo Levi <i30817 at gmail.com>:
> Out of the blue, a few days ago, i wondered if a tuple construct that had
> names,
> ie: (String directory, String file) for instance, would make any sense?
> I know that spaghetti code should be factored to map to simple functions
> with simple return arguments, but i saw sooooo much code that had simple
> container semantics.
> A tuple object written as a compiler code transformation like autoboxing
> would make
> a lot of sense if it allowed names to be defined at use site.
> I'm sure you know that this can be simulated by some creative use of
> generics and static import,
> but the names (one ... first) are pretty bad.
>
> Just throwing a idea, don't bite my head off.
>
>
You need tuples or multiple return values?
I do not see any good reason to introduce tuples.
While no multiple return values is lack in language in my opinion. See
simple method:
(boolean isSucceed, T replaced) replace(T element){
int i = index(element);
if (i<0) return(false,null);
T old = elements[i];
elements[i] = element;
return (true,old);
}
use:
void sample_1(...){
boolean efect = container.replace(element).isSucceed;
...
}
void sample_2(...){
Boo old = container.replace(element).replaced;
...
}
void sample_3(...){
(boolean efect = .isSucceed,Boo old = .replaced) =
container.replace(element);
...
}
void sample_4(...){
final replaced = container.replace(element);
boolean efect = replaced.isSucceed;
Boo old = replaced.replaced;
// forget replaced;
...
}
Did you ever tried to do it now time?
synchronize(container){
T old = container.get(element);
if (old!=null){ // problem if element is null
container.replace(element);
}
}
But there is no point to introduce that if we will have to index results.
I also disagree that maps should be used to obtain that target, while
this can be done in 100% in 'static' way.
--
Pozdrowionka. / Regards.
Lasu aka Marek Kozieł
http://lasu2string.blogspot.com/
More information about the coin-dev
mailing list