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,999932ecc319322a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!mpls-transit-01.news.qwest.net!feed.news.qwest.net!news.uswest.net.POSTED!not-for-mail Newsgroups: comp.lang.ada Subject: Re: advice on package design From: Jared References: <1110212638.336123.298580@l41g2000cwc.googlegroups.com> <1gbk0qx2sgzpg$.sltzfssofla8$.dlg@40tude.net> <3jok3ghqqls8$.1rrsonb8jsurt$.dlg@40tude.net> <88zllqj1min5$.fqqxis9i327d$.dlg@40tude.net> <18e9a92kz25wu$.8b965bel5vef$.dlg@40tude.net> <1dgodaruwhhwo$.1baazg490isjx.dlg@40tude.net> Organization: None User-Agent: Xnews/5.04.25 Message-ID: Date: Fri, 18 Mar 2005 03:06:47 GMT NNTP-Posting-Host: 65.100.229.122 X-Trace: news.uswest.net 1111115207 65.100.229.122 (Thu, 17 Mar 2005 21:06:47 CST) NNTP-Posting-Date: Thu, 17 Mar 2005 21:06:47 CST Xref: g2news1.google.com comp.lang.ada:9579 Date: 2005-03-18T03:06:47+00:00 List-Id: Robert A Duff wrote in news:wccsm2u6k1t.fsf@shell01.TheWorld.com: > But that seems less readable (to me) than just writing > "Initialize_Database;" where I want it to happen. > So a rule (requiring "declare") that is intended to increase > readability actually decreases it. > > And if you want a statement in a package *spec* (say, to initialize > something), it's far worse. There's no direct workaround; you have to > totally rearrange the structure of your design in order to get around > a silly syntax rule. Is this terribly common, though? I'm just a hobbyist, so when I run across something like that, I just assume I have a bad design. > It seems to me that: > > Mumble: T := Blah(...); > > should be precisely equivalent to: > > Mumble: T; > Mumble := Blah(...); > > which should be precisely equivalent to: > > Mumble: T; > Blah(Mumble); > > (where in the last example we replace function Blah with a procedure > with an 'out' parameter). The programmer should be able to switch > from one of these forms to another, without changing the semantics of > the program. But the syntax rules require stirring the code around > when you make these changes. > > (Another reason Ada does not have the above desirable property is that > function results of subtype String behave differently from 'out' > parameters of subtype String. I don't like that.) This is the case for all unconstrained array types. In order to use unconstrained variables, we three distasteful choices. Invoke the entire object mechanism for a single controlled type, fiddle with access types and hope not to drop any references, or create code that looks like: > function F(...) return String is > A: String := ...; > begin > Do_Something(A); > declare > B: constant String := G(A); > begin > ... and so on .................................. > declare > Z: > String ... > begin > return > Z; > > Yuck. There's always Ada.Strings.Unbounded.Unbounded_String, but that's only good for character arrays. Incidentally, I'm just a hobbyist, so I don't know about this; how common is it in production code to declare a controlled type just to guarantee uniqueness of reference? Of those, how many are used for arrays?