Nice to @Share?

Rémi Forax forax at univ-mlv.fr
Tue Feb 23 05:23:35 PST 2010


Le 23/02/2010 11:03, Reinier Zwitserloot a écrit :
> "public" as a keyword on local variable declarations and method parameters
> avoids the need to mess with (restricted) new keywords, is backwards
> compatible,

Reiner,
I think you can introduce any keyword before a local declaration without 
breaking compatibility.
So the best is to choose a keyword that means what you really want.

By the way, I am very happy with final (or implicit final).
When I code and find that I need a non-final local variable,
I first try to rewrite the code to avoid to use non-final
before trying to use a mutable object.

<T> void foreach(List<T> list, #void(T) fun) {
   for(String element: list)
     fun.invoke(element);
}
...
@shared int length = 0;
foreach(alist, #(String element){
    length += element.length;
});

can be rewritten as:

<T> int reduce(List<T> list, #int(T, int) fun, int acc) {
   for(String element: list)
     acc+= fun.invoke(element);
    }
    return acc;
}
...
int length = reduce(alist, #(String element, int acc) {
    return element.length + acc;
});

In my opinion, @Shared is not that important if you provide APIs
to easily play with collections.

[...]

> --Reinier Zwitserloot
>    

Rémi


More information about the lambda-dev mailing list