'This' type
Marek Kozieł
develop4lasu at gmail.com
Sun Mar 15 03:57:43 PDT 2009
2009/3/15 Howard Lovatt <howard.lovatt at iee.org>
> I am not sure I completely follow the proposal, but if the proposal is
> something like self types in Eiffel or Scala then they can have
> problems. In the Eiffel book, I think it is ed. 3 that has self types,
> they are introduced in a Skier example. The example is organising a
> High School Ski Trip and you don't want the boys sharing with the
> girls, so you want the roommate() method to have type this (self in
> Eiffel), so that Boy's roommmate returns a Boy and Girl's roommate()
> returns a Girl. Something like:
>
> interface Skier { This roommate(); void setRoommate(This roomie); ... }
>
> class Boy implements Skier { Boy roommate() ... }
>
> class Girls implements Skier { Girl roommate() ... }
>
> Now they introduce the concept of a Ranked skier and have classes
> RankedBoy and RankedGirl, something like this:
>
> interface Ranked { int ranking(); }
>
> class RankedBoy extends Boy implements Ranking { RankedBoy roommate() ... }
>
> ...
>
> The problem is that now only RankedBoys can share with RankedBoys;
> which was not the intention in the example and is an extremely
> difficult to find bug. This shows that even *expert* programmers can
> make mistakes with self types. Therefore self types seem to solve some
> problems, but introduce others.
>
>
After some time, I found the same about this.
'This' type need lots analyze and it should be split into:
'This' type :
- work with inheritance
- can be used in generics
- but allowed only for return type (would add relation to generics)
- it would be great mistake to allow 'This' as input parameter other than <?
super This>
'Self' type :
- used as replacement current class.
I'll try to finish other specification that will allow return 'this' and
will do interfere with potential added 'This' type.
--
Pozdrowionka. / Regards.
Lasu aka Marek Kozieł
http://lasu2string.blogspot.com/
More information about the coin-dev
mailing list