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=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6aa1ec264ce25142 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.180.24.202 with SMTP id w10mr3228684wif.0.1346247203331; Wed, 29 Aug 2012 06:33:23 -0700 (PDT) Path: e9ni73652844wia.0!nntp.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Wed, 29 Aug 2012 15:33:25 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Real syntax problems in Ada References: <1p5r39cusgc1n$.18nj9sytckk6$.dlg@40tude.net> <289703e7-1fba-41ce-b781-9e58ff2ec7df@googlegroups.com> <1w3xr2kbz8a19$.wpfoz4p1j1sb.dlg@40tude.net> In-Reply-To: Message-ID: <503e1a1d$0$6572$9b4e6d93@newsspool3.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 29 Aug 2012 15:33:17 CEST NNTP-Posting-Host: 8a5b74cf.newsspool3.arcor-online.net X-Trace: DXC=aJLh>_cHTX3jM[GOg@_QZ`4H X-Complaints-To: usenet-abuse@arcor.de Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Date: 2012-08-29T15:33:17+02:00 List-Id: On 29.08.12 12:43, stefan-lucks@see-the.signature wrote: > Indeed, the syntax for declaring a generic something (after the keyword > "generic" the parameters come first, and the something and its name comes > last) is counter-intuitive, different from any other declarations, and > hurts readability. Consider the following simple example: > > generic > type Item is private; > type Many_Items is array(Positive range <>) of Item; > with function "<"(Left, Right: Item) return Boolean is <>; > function Minimum(List: Many_Items) return Item; > > Ask programmers without Ada experience what this is. Most would read this > as a generic declaration of something -- but how many would read this as > the generic declaration of a function called "Minimum"? It is good to see a reference to at least one of the touchstones of readability. > Your idea seems to be to alternatively write the above declaration as > > generic function Minimum > (type Item is private; > type Many_Items is Array (Natural Range <>) of Item; > function "<"(Left, Right: Item) return Boolean is <>) > (List: Many_Items) return Item; > > This would be a lot more readable. (The touchstones of readability are not mentioned here.) Why would a "(" be more readable? I'd like to 2nd any motion for bracketing, but not in *this* way. One issue seems to be: "Where do the generic formals end?" The example replaces, in a sense, the keyword "function" after the formals (Ada style) with a "(" (in suggested style). There may be more "(" among the formals, like there are in the declaration of Many_Items above. When declarations of formals become a little more involved, then a "(" may easily make it to the start of a line, forcing the reader to judge whether or not this "(" is the start of the function's parameter profile. Thus, "if the indentation is lost...", then the brackets will surely leave many at loss. (I don't think that resorting to counting pairs of matching brackets counts as a solution.) Because *) the distance between the function's name and its parameter profile is non-zero, and likely large; *) the distinction between the two kinds of parameters is blurred, not made clear, by overloading () once more; *) using sequences of ()s here introduces ambiguity (in the mind non-compiler readers) as entry families already use sequences of ()s in a similar context, but with different meaning. The real problem for the reader of Ada generics seems to be finding the spot where the generic formals end. Interestingly, this problem is semi-solved in C++ (and Parasail). Semi-solved because C++ template syntax is notorious for its qualities, including >>, but nevertheless, there is no bracketing problem in the sense of brackets marking a start-of-thing, and an end-of-thing: template < bla bla > class T : ... Here, the right angle bracket lets the reader see end of generic formals. Voil�, the usual block structure! Far from wanting to recommend the syntax of C++---why, when even C++ programmers frown upon it, it seems as though, in Ada, the left bracket named "generic" would need some kind of matching right bracket, since then the words "package", "function", and "procedure" will not need to convey two meanings in the case of generic units (end of formals, and kind of unit).