Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Noob question: polymorphic CAT calls in practice

45 views
Skip to first unread message

Andrea Taverna

unread,
Jul 4, 2009, 1:03:55 PM7/4/09
to
Hi folks,

I'm currently looking for a statically-typed OO language with open-
source support and I'm weighing up Eiffel.
I think Eiffell suits nicely, if not perfectly, my needs, however I'm
not comfortable with the CAT call issue.
I think I've understood the theory behind it, after having read the
relevant OOSC chapter and the Recast article; my doubts regard its
practical aspect.

A CAT call may generate a run-time error similar to dereferencing a
void/dangling pointer, since in both cases the program is trying to
access something that doesn't exist. Under this light, a reasonable
way to handle CAT calls at run-time is plain debugging.
The problem comes with 3rdy-party libraries. They can be broken
whenever the client introduces covariance.
Naively, the library author may consider its library as safe a priory
and compile it leaving the job of writing compliant code to the
client.

I'm fine with this solution, but I'm not sure that is enough, there
may be further ramifications for CAT calls that could still break the
code unexpectedly.
More importantly, how eiffel programmers handle this problem in open-
source libraries? Is it possible to have shared libraries in Eiffel?
Are they the norm or the exception?

Finally, which of the solutions proposed in the recast article are in
the current Eiffel standard?

TIA

Andrea

Helmut

unread,
Jul 6, 2009, 6:12:38 AM7/6/09
to
Hello Andrea,

Eiffel has the possibility of catcalls, because it allows covariant
redefinitions and polymorphic attachments. There has not yet been
found a language validity rule which allows to rule out catcalls at
compile time.

It is very simple to find examples with catcalls. However these
examples are usually far from being realistic. In realistic setups,
catcalls rarely happen.

A catcall at runtime is handled by good Eiffel compilers as an
exception. A well designed runtime does not allow that execution
continues with the object of the wrong type. Otherwise a catcall would
be very difficult to debug. But with an exception trace it is usually
very easy to see which call with which object of wrong type caused the
catcall.

I agree, that a compile time solution (i.e. static check) would be
better.

The recast proposal is not part of Eiffel and to the best of my
knowledge no Eiffel compiler has implemented recast.

Regards
Helmut

The Eiffel Compiler: http://tecomp.sourceforge.net
http://www.sourceforge.net/projects/tecomp

Andrea Taverna

unread,
Jul 6, 2009, 5:28:09 PM7/6/09
to
> A catcall at runtime is handled by good Eiffel compilers as an
> exception. A well designed runtime does not allow that execution
> continues with the object of the wrong type. Otherwise a catcall would
> be very difficult to debug. But with an exception trace it is usually
> very easy to see which call with which object of wrong type caused the
> catcall.

I can understand this for the "changed type" part of CAT, since
covariant arguments are anchored, but
what happens with descendant hiding? You would need run-time checks
for every feature access, wouldn't you?

Helmut

unread,
Jul 7, 2009, 10:02:15 PM7/7/09
to

The descendant hiding issue has been resolved in the Eiffel standard
(ECMA Eiffel). Descendant hiding is possible only in the case of non-
conformant inheritance. But in the case of non-conformant inheritance
polymorphic attach is not allowed. Therefore this facet of a catcall
is no longer possible. Under conforming inheritance a feature can only
win clients, but not loose clients.

By the way: The runtime checks described above need to be done only if
there is a chance of a catcall (covariant redefinition and polymorphic
attach). The compiler can rule out this possibility in many cases.
From a performance point of view the remaining runtime checks should
not be significant in the majority of the cases.

0 new messages