On Aug 25, 11:48 am, Romain Pelisse <bela...@gmail.com> wrote:
> > The code behind partition:
> >http://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_8_0_final/sr...
>
> > def partition(p: A => Boolean): (Repr, Repr) = {
> >   val l, r = newBuilder
> >   for (x <- this) (if (p(x)) l else r) += x
> >   (l.result, r.result)
> > }
>
> Well, this brings a new twist into it, isn't it ? Clearly this code is
> shorted than Java - no arguing here, but one could definitely argue that it
> is more complex than the rather plain Java code we saw on the example...
>
IMO this argument is beside the point. The code was presented as an
answer to the argument that you could write the partition method in
Java, and that therefore the original comparison was unfair. The code
demonstrates that you cannot write generic partition in Java, for
three reasons:

1. Partition takes a closure as argument, which is as of today
unavailable in Java.
2. Partition returns a pair as result (and this pair is decomposed by
a pattern match in user code). Neither is available in Java.
3. Partition resides in a trait so that it can be uniformly reusable
for any Scala collection. Traits are not available in Java either.

So the point is that you could not have written partition with
reasonable syntactic overhead in Java. And that means that the OP's
comparison of Scala's user code

 val (minors, adults) = people partition (_.age < 18)

with the longer Java loop is valid. How partition is implemented is
irrelevant. It's like complaining about the code style of the author
of the compiler you are using. And, I accept the argument that
idiomatic Scala does break with quite a few Java conventions; it's not
the same language, after all.

Cheers

 -- Martin

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to javapo...@googlegroups.com.
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to