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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2a687662f09731bb X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!130.81.64.211.MISMATCH!cycny01.gnilink.net!cyclone1.gnilink.net!spamkiller.gnilink.net!gnilink.net!trnddc05.POSTED!20ae255c!not-for-mail Newsgroups: comp.lang.ada From: Anonymous Coward Subject: Re: Ada Quality and Style book discussion ("_Type" suffix) References: <437c5ec8$1_1@glkas0286.greenlnk.net> Message-Id: User-Agent: slrn/0.9.7.4 (Linux) Date: Sat, 19 Nov 2005 21:52:09 GMT NNTP-Posting-Host: 129.44.82.251 X-Complaints-To: abuse@verizon.net X-Trace: trnddc05 1132437129 129.44.82.251 (Sat, 19 Nov 2005 16:52:09 EST) NNTP-Posting-Date: Sat, 19 Nov 2005 16:52:09 EST Xref: g2news1.google.com comp.lang.ada:6485 Date: 2005-11-19T21:52:09+00:00 List-Id: In article <437c5ec8$1_1@glkas0286.greenlnk.net>, Martin Dowie wrote: > Anonymous Coward wrote: >> package Name_Collisions is >> [...] >> type Speed is new Float; >> >> --No can do. "speed" hijacked by type definition. >> -- >> Speed : Speed; >> >> end Name_Collisions; > > But why not use scoping to solve this? I always separate type > declarations from object declarations anyway, so I never see these > sorts of problems. I would prefer not to make my architecture dependant on identifier choices, since packages are much more than just name spaces. If package seperation prevents a name collision, it's only incidental in my case. > Also, I don't think that "Speed" /is/ a good > type name e.g. > > package SI is > type Meters_Per_Second is ...; > end SI; > > package App is > Speed : SI.Meters_Per_Second; > ... > end App; That's getting into the specifics of how a speed might be used. I deliberately try to keep my examples as simple as possible to illustrate my point, so you couldn't see from my example why Speed(_Type) might be a good name - only why "Speed" alone would be a bad name. Here's a slightly more elaborate example: package Physics is type Distance_Type is private; type Speed_Type is private; type Time_Type is private; type Distance_Units_Type is (Meters, Feet, Miles); type Time_Units_Type is (Seconds, Minutes, Hours); function Distance (Distance : in Float; Distance_Units : in Distance_Units_Type) return Distance_Type; function Time (Time : in Float; Time_Units : in Time_Units_Type) return Time_Type; function "/" (Left : in Distance_Type; Right : in Time_Type) return Speed_Type; function "*" (Left : in Speed_Type; Right : in Time_Type) return Distance_Type; function "*" (Left : in Time_Type; Right : in Speed_Type) return Distance_Type; private type Distance_Type is new Float; type Speed_Type is new Float; type Time_Type is new Float; end Physics; In this case, Speed_Type fully leverages encapsulation to keep units of measure as abstract as possible. Internally speed is represented as meters per second, but that is none of the users business, so "Speed" suffixed with "_Type" makes the most sense.