comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Starter project: getopt_long in Ada
Date: Fri, 25 Nov 2011 17:39:31 +0100
Date: 2011-11-25T17:39:32+01:00	[thread overview]
Message-ID: <4ecfc4c4$0$6579$9b4e6d93@newsspool3.arcor-online.net> (raw)
In-Reply-To: <slrnjcushg.vl6.lithiumcat@sigil.instinctive.eu>

On 25.11.11 11:47, Natasha Kerensikova wrote:

> So I wrote a Getopt_Long package, along with a test suite, that can be
> found at:
> http://fossil.instinctive.eu/natools/dir?ci=tip

Looking at Natools.Getopt_Long.Process, there is one design
that I think is less clear than could be, seen from the use
case. If I were to write the event handling procedures, I'd be
noticing that the current design suggests writing a larger number
of "linguistically" unconnected subprograms to be passed
to Process. But, in fact, they will likely be logically connected
subprograms, all to do with parsing the same command line.

I'd prefer these handlers to be "linguistically" collected in
one place (and a different sets of handlers collected in
different places, respectively). In order to achieve this,
an abstract type can state the list of handling procedures,
with null defaults for operations the programmer does not
wish to do anything special. Defining this type has the
advantages that it makes programmers write software organized
into typed structure, yielding

1) definite places to look for the handling procedures
2) handlers that can share common data for communicating
   parsing state among them
3) human readers that know about 1 and 2 because they can
   look for concrete types derived from the abstract type.

I think the advantages outweigh a minor loss in flexibility,
if you'd want to call flexibility the ability to pass a
collection of subprograms each declared just anywhere.

Influencing the shape of this type, Process's parameters
such as Posixly_Correct might mean that the handling
procedures may want to determine whether or not Posixly_Correct
is true.

So, then, my first idea will be along these lines:

package Natools.Handlers is

    type Id_And_Argument_Handler
       (Posixly_Correct :  Boolean;
        ...)
    is abstract tagged private;

    procedure Callback
        (Handler : in out Id_And_Argument_Handler;
         Id : Option_Id;
         Argument : String) is abstract;

    procedure Missing_Argument
        (Handler : in out Id_And_Argument_Handler;
         Id : Option_Id) is null;

    etc.

end Natools.Handlers;


Then, the parameter profile of Natools.Getopt_Long.Process
beceomes shorter:

package Natools.Getopt_Long is

    etc.

    procedure Process
       (...
        Actions : Id_And_Argument_Handler'Class;
        ...);

    etc.

end Natools.Getopt_Long;

I did not look at the implementation.


- Georg



  reply	other threads:[~2011-11-25 16:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-25 10:47 Starter project: getopt_long in Ada Natasha Kerensikova
2011-11-25 16:39 ` Georg Bauhaus [this message]
2011-11-26 18:13   ` Natasha Kerensikova
2011-11-26 20:47     ` Jeffrey Carter
2011-11-28 15:49     ` Georg Bauhaus
2011-11-28 17:18       ` Natasha Kerensikova
2011-11-27  8:21   ` Yannick Duchêne (Hibou57)
2011-11-27 12:30     ` Natasha Kerensikova
2011-11-27 15:11       ` Yannick Duchêne (Hibou57)
2011-11-28  8:21         ` Natasha Kerensikova
2011-11-28 13:02           ` Yannick Duchêne (Hibou57)
2011-11-27  8:05 ` Yannick Duchêne (Hibou57)
2011-11-27 12:39   ` Natasha Kerensikova
2011-11-27 14:52     ` Yannick Duchêne (Hibou57)
2011-11-27  8:09 ` Yannick Duchêne (Hibou57)
replies disabled

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