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-7-bit Received: by 10.180.95.2 with SMTP id dg2mr355675wib.2.1346246068283; Wed, 29 Aug 2012 06:14:28 -0700 (PDT) Path: e9ni63527955wia.0!nntp.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Real syntax problems in Ada Date: Wed, 29 Aug 2012 16:14:32 +0300 Organization: Tidorum Ltd Message-ID: References: <1p5r39cusgc1n$.18nj9sytckk6$.dlg@40tude.net> <289703e7-1fba-41ce-b781-9e58ff2ec7df@googlegroups.com> <1w3xr2kbz8a19$.wpfoz4p1j1sb.dlg@40tude.net> Mime-Version: 1.0 X-Trace: individual.net nLx4dbvmgTWCqWO3ChhGMACW6Ui6i9w92hLn1Z3cGwN9l1+IZmQTp9ExV6x0KNqNeK Cancel-Lock: sha1:hM9oGvC8RuzVpe/nrLrDfCNHnLo= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Date: 2012-08-29T16:14:32+03:00 List-Id: On 12-08-29 13:43 , stefan-lucks@see-the.signature wrote: > On Wed, 29 Aug 2012, Dmitry A. Kazakov wrote: > >> No, I meant rather this: >> >> generic package P (Foo : function return Integer; Q : package...) is ... > > 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"? You may be right, but surely the syntax is very easy to teach and learn: if you want to make a subprogram or a package generic, stick "generic" and the list of generic formals in front of the "package", "procedure" or "function". > If the indention is lost, An artificial assumption. > even Ada-programmers would have problems to find > out *what* is generically declared (a function) and what its name is > ("Minimum"). Not really. Start from the end and scan backwards until you find "package", "procedure", or "function". Or start from the beginning and find "package", "procedure", or "function" that is not immediately preceded by "with". > 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. There is always a different opinion... I think it is much less readable, because the separation between the list of generic formals and subprogram formals is much less visible. If Ada syntax is changed to put the name of the generic unit before the formal parameters, I should want to require "with" before every generic formal, and all within a single set of parentheses. Like this: generic function Minimum ( with type Item is private; with type Many_Items is array (Natural range <>) of Item; with function "<" (Left, Right : Item) return Boolean is <>; List : Many_Items) return Item; But as I said, I much prefer the current syntax. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .