comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Error-names.
Date: Mon, 1 Mar 2004 17:20:51 -0600
Date: 2004-03-01T17:20:51-06:00	[thread overview]
Message-ID: <1047hbljcig7912@corp.supernews.com> (raw)
In-Reply-To: 404243E5.376C42BB@sympatico.ca

"David Marceau" <davidmarceau@sympatico.ca> wrote in message
news:404243E5.376C42BB@sympatico.ca...
...
> Now focus on what it should look like in Ada:
>
> procedure setParametersForServiceX
> (
> OLEORWINDOWSORJNIHANDLEOFSOMESORT
> , ObjectToWorkOn
> , ObjectHoldingParametersToPassToObjectToWorkOn
> );
>
> procedure callServiceX
> (
> OLEORWINDOWSORJNIHANDLEOFSOMESORT
> , ObjectToWorkOn
> );
>
> My variable names and declarations are not Ada standard or C standard but
what's
> important is the placement of parameters and the number of parameters in
the
> service calling pattern to facilitate long term maintenance.  The rule of
thumb
> is there should be no more than three parameters in
setParametersForService and
> no more than two parameters in callService.
...
> I'd love to hear what others think about this.  I'm all ears.

In Ada 95, I don't think this is a great idea, because you lose the
advantages of default parameters. We thought about this a lot in the context
of Claw, and decided having separate parameters was better, because they
could have appropriate defaults, and thus you rarely need to give them.
Moreover, you can add parameters to a routine without changing any calls
simply by giving appropriate defaults to new parameters.

None of this is possible with records, because the aggregates need to be
complete. So if you add a new item, you'll get errors on all of the calls,
even if the new item is relatively unimportant.

For instance, a Claw window create routine could look like:

     procedure Create (Window : in out Window_Type;
                                   Parent : in out Root_Window_Type'Class;
                                   Position : in Point_Type :=
Use_Default_Position;
                                   Size : in Size_Type := Use_Default_Size;
                                   Menu : in Menu_Type := No_Menu;
                                   Title : in String := "";
                                   Show_System_Menu : in Boolean := True;
                                   Show_Close_Box : in Boolean := True;
                                   Allow_Resizing : in Boolean := True;
                                   ...
                                   );

A call could look like:

    Create (New_Window, My_Parent, Size => (100, 100));

While a call using a record would have to give all of the parameters
(components). Yuck.

Ada 200Y will fix this, as there is a way to initialize record components to
defaults:

     (Size => (100, 100), others => <>);

so your technique will work better in the future. But note that it still
won't work well with indefinite parameters (like the Title parameter above).

                         Randy.






      parent reply	other threads:[~2004-03-01 23:20 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-28 12:58 Error-names Martin Klaiber
2004-02-28 13:35 ` Error-names Martin Dowie
2004-02-28 15:26   ` Error-names Martin Klaiber
2004-02-28 17:19     ` Error-names Marius Amado Alves
2004-02-28 18:31       ` Error-names Martin Klaiber
2004-02-28 19:47         ` Error-names tmoran
2004-02-28 20:29           ` Error-names Martin Klaiber
2004-02-29 19:03           ` Error-names Jeffrey Carter
2004-02-29 20:04             ` Error-names tmoran
2004-02-29 23:24               ` Error-names Björn Persson
2004-03-01 11:29                 ` Error-names Martin Klaiber
2004-03-01 12:48                   ` Error-names Marius Amado Alves
2004-03-02  2:15                     ` Error-names Jeffrey Carter
2004-02-29 20:33             ` Error-names Martin Klaiber
2004-02-29 23:43               ` Error-names tmoran
2004-03-01 11:20                 ` Error-names Martin Klaiber
2004-03-07 15:10                   ` Error-names Björn Persson
2004-03-08  5:42                   ` Error-names Dave Thompson
2004-02-28 20:26         ` Error-names Jacob Sparre Andersen
2004-02-28 18:29 ` Error-names Alexandre E. Kopilovitch
2004-02-29  5:30 ` Error-names David Marceau
2004-02-29 12:17   ` Error-names Martin Klaiber
2004-02-29 19:56     ` Error-names David Marceau
2004-02-29 21:57       ` Error-names Martin Klaiber
2004-03-01 23:20       ` Randy Brukardt [this message]
replies disabled

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