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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,20bf0d0544bba2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-09 10:47:30 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!easynews.com!easynews!elnk-pas-nf1!elnk-nf2-pas!newsfeed.earthlink.net!attbi_feed3!attbi_feed4!attbi.com!attbi_s53.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Declaring subtypes References: <95476e79.0312090710.68a031a4@posting.google.com> X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 24.6.133.123 X-Complaints-To: abuse@comcast.net X-Trace: attbi_s53 1070995641 24.6.133.123 (Tue, 09 Dec 2003 18:47:21 GMT) NNTP-Posting-Date: Tue, 09 Dec 2003 18:47:21 GMT Organization: Comcast Online Date: Tue, 09 Dec 2003 18:47:29 GMT Xref: archiver1.google.com comp.lang.ada:3288 Date: 2003-12-09T18:47:29+00:00 List-Id: > ... wondering if declaring subtypes of String for common database > fields was overkill. > ... > subtype Address_Line is String(1..60); > subtype City is String(1..40); > ... > I understand that Strong typing is one of the strengths of Ada but I > just don't know how far to go with it. Strong typing has to do with the compiler warning you when you try to mix type Apples with type Oranges. Subtypes merely specify a constraint. So Address_Line and City are both of type String and Home : Address_Line; Home_City : City; ... Ada.Text_IO.Put_Line(Home & ", " & Home_City); Home(1 .. 40) := Home_City; does not violate strong typing and is OK (as far as the compiler can tell). If you have a database where City is always 40 characters (blank padded, perhaps), then subtype City is String(1..40); is eminently reasonable. Ditto for Address_Line etc. If City is of varying lengths though, you might want to use the facilities of Ada.Strings.Bounded or Ada.Strings.Unbounded instead. If you want to use strong typing so the compiler will warn you about mixed types then you need type Address_Line is new String(1..60); type City is new String(1..40); If you do that, then Home(1 .. 40) := Home_City; will generate an error message from the compiler. That may be useful in catching coding errors. OTOH, Ada.Text_IO.Put_Line(Home & ", " & Home_City); will also generate an error message, which is probably not so helpful. To accomplish the same thing you would have to write something like Ada.Text_IO.Put_Line(String(Home) & ", " & String(Home_City)); Whether the error checking benefits outweigh the verbosity of the extra type conversions depends of course on the characteristics of your particular application. In this particular example, for instance, changing the variable "Home" to "Home_Street" would probably lessen errors like Home_Street(1 .. 40) := Home_City; so it probably wouldn't be worthwhile to go for full separate string types.