[concurrency-interest] jsr166y.forkjoin.Ops vs the world outside

Mark Mahieu mark at twistedbanana.demon.co.uk
Mon Feb 11 21:00:06 EST 2008

> Have you thought about inverting the names, i.e.
> public class ToBoolean {
>     public interface OfBoolean {
>         boolean of(boolean arg0);
>     }

I did consider something similar (your naming is better), but it  
didn't seem to work too well for Generator or Predicate.  Worth a  
second look perhaps.

Another option I tried was having Op, BinaryOp, Predicate, Reducer  
etc as (generic) interfaces in java.util, alongside the existing  
Comparator interface, and declaring the specialized versions of each  
as nested interfaces.

> client use:
>     final Predicate.OfInt predicate = new Predicate.OfInt() {
>             public boolean of(int arg0) {
>                 ...
>             }
>         };

That's nice, though I think many people would reach for static  
imports when possible, in which case the succinct naming could end up  
backfiring a little.

> Note also that rather than naming the method "op", I named them
> "of" which seems to read better; "on" is also an option:

'of' works quite well in the sense that many people use it when  
talking about generic types - "List 'of' Strings" for example.

> Another nice side effect is that the package level javadoc does not  
> look too awful.


>> or we improve the
>> language somehow so that it becomes unnecessary for them to do so.
> where are these language extensions being proposed?

There's plenty of talk about 'fixing' or 'improving' generics in  
various ways, including making them work with primitive types, which  
could solve all this if done well enough.  I haven't seen any  
workable proposals though - the ideas I've read either break  
compatibility somewhere or tackle the problem with some form of  
boxing/unboxing, which is a can of worms in itself.

On the flip-side there's BGGA's function types of course, which seem  
to be orthogonal to generics improvements, and are able to offer  
certain benefits due to being targeted at a specific problem (n-ary  
ops, naturally covariant/contravariant type params, etc).  I suspect  
that they also present opportunities for VM-level optimization.

But I doubt I'm telling you anything new, so I'd better stop there ;-)

> -- 
> David J. Biesack     SAS Institute Inc.
> (919) 531-7771       SAS Campus Drive
> http://www.sas.com   Cary, NC 27513


More information about the Concurrency-interest mailing list