comp.lang.ada
 help / color / mirror / Atom feed
From: stefan-lucks@see-the.signature
Subject: Re: Real syntax problems in Ada
Date: Wed, 29 Aug 2012 12:43:16 +0200
Date: 2012-08-29T12:43:16+02:00	[thread overview]
Message-ID: <Pine.LNX.4.64.1208291146070.20257@medsec1.medien.uni-weimar.de> (raw)
In-Reply-To: <a7fajtasftcd.wpdq5ukic2ny.dlg@40tude.net>

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"?

If the indention is lost, even Ada-programmers would have problems to find 
out *what* is generically declared (a function) and what its name is 
("Minimum").

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 problem with that could be distinguishing generic and non-generic
> signatures of generic subroutines:
> 
>    generic procedure Baz (X : Integer);
> 
> Is X here a generic formal object or a plain argument of Baz?

Here we are hurt by another minor but annoying inconsistency of the Ada 
syntax. Almost everywhere, we have to write "null" to make it explicit if 
we ask for nothing, or for nothing additional. E.g., we must write

  type X is new Tagged_Type with null record;

instead of 

  type X is new Tagged_Type;

Similarly, we write "if B then null; else Do_Something end if;" instead of 
"if B then else Do_Something end if;". This is an advantage of Ada that 
improves readability and helps to catch flaws.  

Back to the issue you raised! 

If we introduce the notation "(null)" for empty parameter lists, we can 
easily solve your issue:

   generic procedure Baz_1 (with X: Integer) (null);
     -- X is a generic formal object, 
     -- (I am not sure if we should allow or even require "with" here.)

   generic procedure Baz_2 (null) (X: Integer);
     -- X is a plain argument



-- 
---- Stefan.Lucks (at) uni-weimar.de, University of Weimar, Germany  ----
    <http://www.uni-weimar.de/cms/medien/mediensicherheit/home.html>
------  I  love  the  taste  of  Cryptanalysis  in  the  morning!  ------




  reply	other threads:[~2012-08-29 11:37 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-28  8:13 Real syntax problems in Ada Dmitry A. Kazakov
2012-08-28 10:20 ` Georg Bauhaus
2012-08-28 10:47 ` Niklas Holsti
2012-08-28 11:33   ` J-P. Rosen
2012-08-31 13:35     ` Robert A Duff
2012-08-28 13:27 ` Vasiliy Molostov
2012-08-28 15:23   ` Dmitry A. Kazakov
2012-08-28 20:18     ` Vasiliy Molostov
2012-08-29  7:25       ` Dmitry A. Kazakov
2012-08-29 10:47         ` Vasiliy Molostov
2012-08-29 11:58           ` Dmitry A. Kazakov
2012-08-30 17:38             ` Vasiliy Molostov
2012-08-28 15:14 ` Adam Beneschan
2012-08-28 16:18   ` J-P. Rosen
2012-08-28 16:39   ` Dmitry A. Kazakov
2012-08-28 21:38     ` Randy Brukardt
2012-08-29  6:58       ` Dmitry A. Kazakov
2012-08-29 10:43         ` stefan-lucks [this message]
2012-08-29 10:58           ` stefan-lucks
2012-08-29 13:14           ` Niklas Holsti
2012-08-29 17:52             ` stefan-lucks
     [not found]             ` <fbps38pgcuf8fgioptt39s6u7dme1aqs7r@invalid.netcom.com>
2012-09-02 10:16               ` svaa
2012-08-29 13:33           ` Georg Bauhaus
2012-08-29 17:20             ` Jeffrey Carter
2012-08-29 17:51             ` stefan-lucks
2012-08-30  9:12               ` Georg Bauhaus
2012-08-28 21:49   ` Randy Brukardt
2012-08-28 23:09     ` Adam Beneschan
2012-08-29  7:34     ` Egil Høvik
2012-08-28 19:41 ` Florian Weimer
2012-08-28 20:53   ` Shark8
2012-08-28 21:07     ` Adam Beneschan
2012-08-28 21:25       ` Shark8
2012-08-28 22:59         ` Adam Beneschan
2012-08-29  7:06       ` Dmitry A. Kazakov
2012-08-30 21:08         ` Randy Brukardt
2012-08-30 22:06 ` sbelmont700
2012-08-30 22:34   ` Adam Beneschan
2012-08-30 22:54     ` William Findlay
2012-08-31  7:39     ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox