From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,b87849933931bc93 X-Google-Attributes: gid109fba,public X-Google-Thread: fac41,b87849933931bc93 X-Google-Attributes: gidfac41,public X-Google-Thread: 103376,b87849933931bc93 X-Google-Attributes: gid103376,public X-Google-Thread: f43e6,b87849933931bc93 X-Google-Attributes: gidf43e6,public X-Google-Thread: 1108a1,b87849933931bc93 X-Google-Attributes: gid1108a1,public X-Google-Thread: 114809,b87849933931bc93 X-Google-Attributes: gid114809,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: OO, C++, and something much better! Date: 1997/01/23 Message-ID: #1/1 X-Deja-AN: 211715305 references: organization: The Mitre Corp., Bedford, MA. newsgroups: comp.lang.c++,comp.lang.smalltalk,comp.lang.eiffel,comp.lang.ada,comp.object,comp.software-eng Date: 1997-01-23T00:00:00+00:00 List-Id: In article 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. If you call a tail a leg, how many legs does a dog have? 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. 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;" -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...