So I'm imagining that we have an abstract Either class, then two concrete
subclasses, Left and Right

The returned value can be either of these, so it holds either a valid file
handle (Left) or an error (Right).

In Java, the "lazy programmer" solution for quickly hacking together a
working solution is to just always cast to Left and retrieve the handle,
which should work in the majority of cases.  Given the absence of pattern
matching (other than exception handlers), the only check that you've used
the API as expected will come at runtime, when the function call actually
returns Right and you get a ClassCastException.  Pattern matching simplifies
matters here a great deal.

It's a shame that CheckedExceptions have to be used in this manner,
especially given that this isn't exactly an "Exceptional" case, and that
they aren't exactly cheap.  Exceptions cost a lot, both in terms of
performance, and in terms of convoluted control flow that's harder to
maintain.

On 22 September 2010 06:19, Ricky Clarkson <[email protected]> wrote:

>   if a previously valid file vanishes while you're working on it, that's
>> unlikely to be recoverable
>>
>
> Entirely false.
>
>  - fileOpen returns Either<FileHandle, Exception>
>> best yet, but the language would need pattern matching for this to work,
>> and a static check that any such match is exhaustive
>>
>
> Either does not require pattern matching, it just benefits greatly.
>
>>
>>   --
> You received this message because you are subscribed to the Google Groups
> "The Java Posse" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<javaposse%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.
>



-- 
Kevin Wright

mail / gtalk / msn : [email protected]
pulse / skype: kev.lee.wright
twitter: @thecoda

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

Reply via email to