comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Use of declare blocks
Date: Fri, 23 Mar 2007 00:15:57 -0500
Date: 2007-03-23T00:15:57-05:00	[thread overview]
Message-ID: <etvnnk$m08$1@jacob-sparre.dk> (raw)
In-Reply-To: %CIMh.1791$rj1.394@newssvr23.news.prodigy.net

<adaworks@sbcglobal.net> wrote in message
news:%CIMh.1791$rj1.394@newssvr23.news.prodigy.net...
>
> "Randy Brukardt" <randy@rrsoftware.com> wrote in message
> news:etveau$g29$1@jacob-sparre.dk...
> >
> > Anyway, I do understand the readability concerns, but I think they're
> > overblown. If you have to look 5 pages away to find a variable
declaration,
> > the readability of the code it is used in isn't necessarily enhanced:
you're
> > still flipping back and forth. Moreover, trying to come up with good
names
> > for code that are made into subprograms just to keep the code "short" is
> > hard, and I know I'm not good at it. These supposed helpers are a real
> > headache during maintenance, because its rarely obvious what they do!
How do
> > that help readability??
> >
> Actually, you make my point for me.  We certainly do not want to look
> all over the place for the name of a variable.   On reason I like to use
> in-lined procedures instead of declare blocks is the ease of grouping
> like things together.   Consider this contrived example:
>
>           case X is
>               when C1  =>  declare
>                                            xxxxxx
>                                      begin
>                                             -- fifty lines of code
>                                      end;
>               when C2 =>   declare
>                                              zzzzzzzz
>                                      begin
>                                             - twenty lines of code
>                                      end;
>               when ...
>           end case;
>
> Even when we label the declare blocks, which I tend to do,
> this can get to be difficult to read and difficult to maintain.  I
> might do this:
>
>            procedure some_unit_name is
>                  procedure C1_Process is ... end C1_Process;
>                  pragma Inline (C1_Process);
>                  procedure C2_Process is ... end C2_Process;
>                  pragma Inline (C2_Process);
>                  -- more procedures as needed
>           begin
>                  -- set up stuff
>
>                  case X is
>                       when C1  =>  C1_Process;
>                       when C2 =>   C2_Process;
>                       when ...
>                  end case;
>            end some_unit_name;

Ahhh, but this is unrealistic, for a couple of reasons.

First, you have to access the local variables and parameters of
Some_Unit_Name from the xx_Process routines. (I don't want to think about
routines that only use global variables!) Those necessarily will be far
away, and not even in the same scope (especially if you succeed in compiling
these separately - in which case they'll be in a different file. You can
pass them all as parameters, but then you're adding to the clutter that
you're supposedly reducing.

Second, you're not taking into account the likelyhood that some of the
processing is the same in several of these branches. That argues for making
that similar processing into a subprogram, too, and pretty soon you have
dozens of subprograms doing small parts of the processing.

And I'm not even going to point out that naming these "sub" routines is very
hard, because they tend to be only part of the processing (especially if
some action for all of the cases happens afterwards, which is common). You
can make it a bit easier sometimes by splitting the code into even more
subprograms, but all of the "noise" of a subprogram isn't going to
necessarily improve the readability.

...
> In your case, you and the small number of programmers who work
> with you are intimately familiar with the code.

That's no excuse for using a bad organization. I know how hard it is to go
back to code you haven't touched in a couple of years. It doesn't matter if
you wrote it originally: you won't remember much about it.

> One of the benefits of
> Ada is that it makes it easier to manage turnover, reassignments, and
> all the other personnel movements that occur in a large software
> organization.   I have seen declare blocks used in an ad hoc manner
> where the lack of documentation created difficulties for newcomers
> to a project.  Giving something a specific, meaningful name can help,
> especially when it is the name of a procedure along with good names
> for the local variables used to make it work.

True enough; but good names are very hard to come up with. (We never
succeeded at that for maybe 50% of the routines in Janus/Ada. Quick: tell me
the difference between "Base_Type" and "Formal_Base_Type" and
"Almost_Base_Type" and "Matching_Base_Type"! :-)

And it's almost a waste of effort to come up with names for throw-aways,
much less good names. I still often use the Fortran "I" for the loop
parameter of a for loop. The name is nearly irrelevant a lot of the time
(and the need for it is really a deficiency of the language -- I want to do
something to all of the components of an array; naming each one in turn is
not really necessary for that purpose). [I do try to use a better name if
the loop is going to longer than a few lines.]

Anyway, declare blocks are so close to subprograms that there isn't that
much difference between them. Surely naming is more important than that??

> I suppose we simply use the coding style most appropriate to the context
> in which we are working.   As I noted, I am not opposed to declare blocks,
> but I am uncomfortable when large systems are designed so they rely
heavily
> on them.   Most organizations don't have the luxury of a stable workforce.

I don't find small blocks to matter much at all - they just serve to narrow
the scope of objects as much as possible, which is important if you're not
going to use something anymore (let it get cleaned up).

I also use locks extensively in some code; those are always controlled
objects so they work properly when an exception propagates. The only way to
control the locking time is with a declare block, and it provides a nice
visual bracket for this use.

                                        Randy.





  reply	other threads:[~2007-03-23  5:15 UTC|newest]

Thread overview: 167+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1172144043.746296.44680@m58g2000cwm.googlegroups.com>
     [not found] ` <slrnetr31o.875.Marc.Boyer@localhost.localdomain>
     [not found]   ` <1172161751.573558.24140@h3g2000cwc.googlegroups.com>
     [not found]     ` <slrnetri6j.875.Marc.Boyer@localhost.localdomain>
     [not found]       ` <546qkhF1tr7dtU1@mid.individual.net>
2007-02-23  8:09         ` why learn C? Marc Boyer
2007-03-20 17:37           ` adaworks
2007-03-21  8:07             ` Maciej Sobczak
2007-03-21 13:39               ` Martin Krischik
2007-03-22  7:54                 ` Maciej Sobczak
2007-03-21 14:10               ` Dmitry A. Kazakov
2007-03-21 17:57                 ` adaworks
2007-03-21 18:48               ` adaworks
2007-03-21 18:39                 ` Georg Bauhaus
2007-03-21 20:09                 ` Dmitry A. Kazakov
2007-03-21 20:25                 ` Use of declare blocks Randy Brukardt
2007-03-21 20:36                   ` Gautier
2007-03-21 20:37                   ` Gautier
2007-03-21 20:43                   ` Niklas Holsti
2007-03-21 21:29                     ` Randy Brukardt
2007-03-22  1:17                       ` Adam Beneschan
2007-03-22  8:34                     ` Dmitry A. Kazakov
2007-03-22  1:06                   ` Adam Beneschan
2007-03-22 17:59                   ` adaworks
2007-03-23  2:35                     ` Randy Brukardt
2007-03-23  5:23                       ` adaworks
2007-03-23  5:15                         ` Randy Brukardt [this message]
2007-03-23 10:20                           ` Georg Bauhaus
2007-03-23 18:25                             ` commenting, was " tmoran
2007-03-24  0:32                               ` adaworks
2007-03-24  2:12                                 ` tmoran
2007-03-24  3:19                                   ` Randy Brukardt
2007-03-24  7:36                                     ` tmoran
2007-03-24 15:35                                       ` Simon Wright
2007-03-21 13:29             ` why learn C? Alexander E. Kopilovich
2007-03-30  0:51             ` kevin  cline
2007-03-30  4:09               ` Steve
2007-03-30  4:58                 ` kevin  cline
2007-03-30  7:44                   ` Lutz Donnerhacke
2007-03-30  9:09                     ` Dmitry A. Kazakov
2007-04-02  4:29                       ` kevin  cline
2007-04-02  6:45                         ` adaworks
2007-04-02  7:52                         ` Dmitry A. Kazakov
2007-04-02  8:19                           ` kevin  cline
2007-04-02 12:04                             ` Dmitry A. Kazakov
2007-04-02 23:37                             ` Randy Brukardt
2007-04-03 12:42                               ` Erasing inappropriate operations (was: why learn C?) Ludovic Brenta
2007-04-03 23:44                                 ` Randy Brukardt
2007-04-04  8:34                                   ` Erasing inappropriate operations Ludovic Brenta
2007-04-04 22:00                                     ` Randy Brukardt
2007-04-03  0:16                         ` why learn C? Markus E Leypold
2007-04-04 16:14                           ` jayessay
2007-04-05  7:14                             ` Hyman Rosen
2007-04-05 15:35                               ` jayessay
2007-04-06  2:02                                 ` Hyman Rosen
2007-04-06  5:57                                   ` Ray Blaak
2007-04-06 11:01                                     ` Markus E Leypold
2007-04-07 23:00                                       ` Ray Blaak
2007-04-08 19:41                                         ` jayessay
2007-04-09 14:08                                         ` Markus E Leypold
2007-04-10 15:48                                           ` jayessay
2007-04-08 19:44                                       ` jayessay
2007-04-06 18:05                                     ` jayessay
2007-04-06 22:00                                       ` Hyman Rosen
2007-04-06 23:46                                         ` jayessay
2007-04-06 23:59                                         ` jayessay
2007-04-06 22:16                                     ` Hyman Rosen
2007-04-06 23:52                                       ` jayessay
2007-04-07  0:39                                         ` Ray Blaak
2007-04-06 17:52                                   ` jayessay
2007-03-30  8:29                   ` Markus E Leypold
2007-03-30  8:35                     ` Markus E Leypold
2007-03-30 17:39                   ` adaworks
2007-03-31 14:59                     ` Steve
2007-03-31 15:59                       ` Markus E Leypold
2007-04-01 14:32                         ` Ed Falis
2007-04-02  7:03                         ` adaworks
2007-03-31 15:14                     ` Pascal Obry
2007-04-02  5:27                     ` kevin  cline
2007-04-02  6:04                       ` Harald Korneliussen
2007-04-02  6:33                       ` Shortage on C / C++ experts Martin Krischik
2007-04-02  7:07                       ` why learn C? adaworks
2007-04-02  7:18                         ` kevin  cline
2007-04-02 13:00                       ` adaworks
2007-04-12 15:28                         ` Hyman Rosen
2007-04-12 18:32                           ` Robert A Duff
2007-04-13 15:59                             ` Hyman Rosen
2007-04-14 22:20                               ` Robert A Duff
2007-04-14 22:46                                 ` Randy Brukardt
2007-04-22 18:53                           ` adaworks
2007-04-22 19:50                             ` Gautier
2007-04-03  0:26                       ` Markus E Leypold
2007-04-03  0:34                       ` Markus E Leypold
2007-04-03  2:22                       ` jimmaureenrogers
2007-04-12 15:47                         ` Hyman Rosen
2007-04-12 16:18                           ` Markus E Leypold
2007-04-13 23:18                             ` kevin  cline
2007-04-14  9:38                               ` Georg Bauhaus
2007-04-14 10:57                               ` Markus E Leypold
2007-04-15 15:10                                 ` Simon Wright
2007-04-15 16:05                                   ` Markus E Leypold
2007-04-15  0:59                             ` Hyman Rosen
2007-04-15 15:28                               ` Markus E Leypold
2007-04-12 16:39                           ` Dmitry A. Kazakov
2007-04-12 20:54                             ` Georg Bauhaus
2007-04-12 20:33                               ` Dmitry A. Kazakov
2007-04-12 21:40                                 ` Georg Bauhaus
2007-04-12 20:50                                   ` Dmitry A. Kazakov
2007-04-13  0:32                                   ` Markus E Leypold
2007-04-14 22:27                                     ` Robert A Duff
2007-04-14  1:20                           ` jimmaureenrogers
2007-04-02  5:03                   ` Brian May
2007-04-02  6:16                     ` kevin  cline
2007-04-03  0:00                       ` Brian May
2007-04-12 15:56                         ` Hyman Rosen
2007-04-12 16:19                           ` Markus E Leypold
2007-04-13 23:42                             ` Georg Bauhaus
2007-04-03  0:13                       ` Markus E Leypold
2007-04-02 11:47                 ` Shortage on C / C++ experts Larry Kilgallen
2007-04-02 12:01                   ` Ludovic Brenta
2007-04-02 12:15                     ` Dmitry A. Kazakov
2007-04-02 18:47                       ` Alexander E. Kopilovich
2007-04-02 20:43                         ` tmoran
2007-03-30  4:52               ` why learn C? jimmaureenrogers
2007-03-30  6:30                 ` Case Crab
2007-03-30  6:37                   ` Gautier
2007-03-30  9:17                   ` Georg Bauhaus
2007-03-31 13:18                     ` Peter C. Chapin
2007-04-01  1:23                       ` Georg Bauhaus
2007-04-01 11:59                         ` Peter C. Chapin
2007-04-02  6:37                       ` kevin  cline
2007-04-02  9:39                         ` Harald Korneliussen
2007-03-30 17:47                   ` adaworks
2007-03-30 19:25                     ` Markus E Leypold
2007-03-30 20:29                     ` Randy Brukardt
2007-03-31  9:52                       ` Dmitry A. Kazakov
2007-04-01  1:35                       ` adaworks
2007-03-31  2:41                   ` jimmaureenrogers
2007-03-31 12:25                     ` not NASA Ada coding standard Stephen Leake
2007-03-31 15:44                       ` Markus E Leypold
2007-04-01 16:22                       ` Simon Clubley
2007-04-02 10:08                         ` Stephen Leake
2007-04-02  7:43                     ` why learn C? kevin  cline
2007-04-02  8:45                       ` Martin Krischik
2007-04-02 10:54                       ` Georg Bauhaus
2007-04-12 16:05                         ` Hyman Rosen
2007-04-12 16:48                           ` Dmitry A. Kazakov
2007-04-12 18:27                           ` Robert A Duff
2007-04-13 16:21                             ` Hyman Rosen
2007-04-12 21:11                           ` Georg Bauhaus
2007-04-13 15:45                             ` Hyman Rosen
2007-04-02  8:13                     ` kevin  cline
2007-04-02 23:54                       ` Randy Brukardt
2007-04-03  2:58                       ` jimmaureenrogers
2007-04-12 16:24                       ` Hyman Rosen
2007-04-12 18:05                         ` Markus E Leypold
2007-04-15  0:55                           ` Hyman Rosen
2007-04-15  7:55                             ` Dmitry A. Kazakov
2007-04-15 15:25                             ` Markus E Leypold
2007-03-31 11:40                 ` Larry Kilgallen
     [not found]                 ` <1175236212.771445.135460@y66g2Organization: LJK Software <c82IfUV$xbi8@eisner.encompasserve.org>
2007-03-31 18:56                   ` adaworks
2007-03-31 20:10                     ` Markus E Leypold
2007-04-01 18:13                       ` tmoran
2007-03-31 19:33                   ` Cesar Rabak
2007-03-31 20:11                     ` Markus E Leypold
2007-03-30  8:16               ` Markus E Leypold
2007-03-30  9:10               ` Georg Bauhaus
2007-03-30 19:16               ` Pascal Obry
2007-04-01 11:41                 ` Martin Krischik
2007-04-01 17:03                   ` Pascal Obry
2007-04-01 18:13                   ` tmoran
2007-04-16  2:09             ` Brian May
replies disabled

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