Newsgroups: comp.lang.c++,comp.lang.smalltalk,comp.lang.eiffel,comp.lang.ada,comp.object,comp.software-eng
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel-eecis!gatech!news.sprintlink.net!news-peer.sprintlink.net!news.bbnplanet.com!cpk-news-hub1.bbnplanet.com!feed1.news.erols.com!news.ecn.uoknor.edu!munnari.OZ.AU!news.mel.connect.com.au!news.syd.connect.com.au!syd.csa.com.au!news
From: donh@syd.csa.com.au (Don Harrison)
Subject: Re: OO, C++, and something much better!
X-Nntp-Posting-Host: dev50
Message-ID: <E4I22L.8B7@syd.csa.com.au>
Sender: news@syd.csa.com.au
Reply-To: donh@syd.csa.com.au
Organization: CSC Australia, Sydney
References: <EACHUS.97Jan23104846@spectre.mitre.org>
Date: Fri, 24 Jan 1997 06:30:20 GMT
Lines: 82
Xref: glinda.oz.cs.cmu.edu comp.lang.c++:242595 comp.lang.smalltalk:49821 comp.lang.eiffel:17600 comp.lang.ada:56367 comp.object:60224 comp.software-eng:52904

Robert I. Eachus writes:

:In article <E4DvAz.G06@syd.csa.com.au> donh@syd.csa.com.au (Don Harrison) writes:
:
:  > That's one view. Another view is to consider such 'subtypes' as
:  > types in their own right. This is more honest, IMO. Using this
:  > definition, neither Ada nor Eiffel is 'type-safe'.
:
:   I'm not trying to start a flame war here but the distinctions
:between types and subtypes in Ada are subtle, and semantic games like
:this don't help.

It may appear to be a game but the purpose of playing it is to find a 
basis for meaningful comparison (between Ada and other languages).

:   If you call a tail a leg, how many legs does a dog have?

4 ... if the dog is an amputee. :)

:   When it comes to computer language definitions, only the reference
:manual can do redefinitions like that for technical terms.  In Ada,
:subtype is a technical term, and is clearly very different from a
:type: A type declaration creates an (anonymous) type, and a (named and
:possibly constrained) first subtype.  A subtype declaration creates
:only a name for a subtype of some already defined type.  In fact all
:of the differences between:
:
:   type Foo is new Integer range 1..10;
: 
:      and 
:
:   subtype Foo is Integer range 1..10;
:
:      are because the first declaration actually creates a type and
:several operations on that type, and the second declaration creates a
:shorthand for a subtype mark and possibly a constraint.  As a language
:lawyer, I feel compelled to point out that a subtype declaration in
:Ada can define attributes--but so can object declarations.  In the
:example above, Foo'First is 1, not Integer'First.  In any case
:attributes which are functions are operations of the (anonyomus) type,
:not of the subtype, so a type and all its subtypes always share the
:same operations:
:
:    subtype Foo is Integer range 1..10;
:    Bar: Integer := 1234;
:    Bar_Image: String := Foo'Image(Bar);
:   
:    gives Bar_Image the value " 1234".  Yes, the subtype declaration
:did declare a function Foo'Image, but its parameter is of subtype
:Foo'Base.  The terminology is tricky here, Foo'Base is not a subtype
:of Foo or of Integer, it is a subtype of the anonymous type created by
:the declaration of Integer in Standard.  Normal (but fuzzy) usage is
:to say that the type of the parameter to Foo'Image is Integer, not Foo.
:
:    There are places in Ada where a subtype_mark is permitted but not
:a subtype_indication, which is a subtype_mark with an explicit
:constraint.  However, this is for stylistic reasons and to simplify
:the order of elaboration.  In fact the big difference between Ada
:subtypes and C macros used as type names is that in Ada the
:expressions are evaluated at the point of the subtype declaration.

Thanks for the background.

:     In Ada it is not unusual to see subtype declarations like:
:
:     subtype Short is Really_Long_Package_Name.Short;
:
:     used solely as a renaming.  To quote RM95 8.5(6 & 7): "A subtype
:defined without any additional constraint can be used to achieve the
:effect of renaming another subtype (including a task or protected
:subtype) as in
:
:      "subtype Mode is Ada.Text_IO.File_Mode;"

Some may choose to do this but I would regard it as a misuse of sub-types.


Don.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Don Harrison             donh@syd.csa.com.au


