"Violating TCP" is a phrase that BGGA and Neal have popularised and
occurred without challenge until FCM came along.

The truth is that the phrase only tells half the story. In the example
Ben gives, it is true to say that you want return to mean 'return from
the enclosing method'. That is because the user believes they are
working with a control statement (such as using). This concept becomes
long returns, and as a result adds a lot of complexity to the spec
(implementing long returns in Java is very difficult, with one
technique being throwing an exception that is higher than Throwable in
the hierarchy!).

It should be pointed out that you can implement control abstraction,
like the using statement, either directly (like for-each or ARM) or
indirectly (something like macros), without needing long returns
themselves.

Where the issue is much more complex is inline closures. These are
closures that perform a single inline task like filtering or event
handling and can today be implemented using a SAM interface.

BGGA argues that this closure is the same language concept as control
abstraction, and thus heads off to create a new type of return
statement (last-line-no-semicolon) and semantics for return that
conflict with inner classes and have the potential for new runtime
errors. The impact of this use of return can be some very subtle bugs
in user code.

FCM argues that control abstraction and inline closures are two
different language changes, and that for inline closures the best
approach *for Java* is to treat return in the same way as in inner
classes. This is simple for developers to learn (based on knowledge of
inner classes), and avoids the nasty runtime exceptions of BGGA.

So, FCM both violates and follows Tennants Correspondance Principle.
But that is in fact a very good thing, something that a naive
statement of "violates TCP" fails to appreciate.

Stephen


On Jan 16, 12:24 pm, Ben Schulz <[email protected]> wrote:
> using(closeable, Block() {
>    // old code
>    someMap.get(this); // ouch
>    // more old code
>
> });
>
> In a pure language (which Java is by no means) this would happen all
> the time, because e.g. if-else is implemented as a message on Boolean
> (hello Smalltalk). In those languages the violation of TCP would be a
> major annoyance, but at least you would get used to it. In Java it
> would simply be a source of evil evil *evil* bugs!

--~--~---------~--~----~------------~-------~--~----~
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