comp.lang.ada
 help / color / mirror / Atom feed
From: dennison@telepath.com (Ted Dennison)
Subject: Re: Let's change semantics of "use type"
Date: 12 Nov 2002 07:39:40 -0800
Date: 2002-11-12T15:39:40+00:00	[thread overview]
Message-ID: <4519e058.0211120739.4f744784@posting.google.com> (raw)
In-Reply-To: B9F5F98B.5DE7%R_Tim_Coslet@pacbell.net

"R. Tim Coslet" <R_Tim_Coslet@pacbell.net> wrote in message news:<B9F5F98B.5DE7%R_Tim_Coslet@pacbell.net>...
> The only real use I have ever found in Ada95 for rename is when I need to
> make repeated references to the same array element in several places in a
> block of code. I rename the array element (to tell the compiler to index it
> only once) then use the new name in the places in the code that reference
> it.
> 
> Example:
> 
>     declare
>         Selected_Item : Some_Typ renames Big_Arrayo_of_Data(x,y,z);
>     begin
>         if Selected_Item = Special_Value then
>             y := Complex_Function(Selected_Item,z);
>             ... more code refering to Selected_Item ...
>         end if;
>         Selected_Item := Fancy_Function(x,i);
>     end;

Were it me, I'd replace this entire declare block with a routine. In
fact, were I to come across this in code I was reading, I'd certianly
refactor it as such. The interfaces into and out of a routine are much
narrower and better defined, so they are far better from a maintanence
(and code understanding) standpoint.

In fact, its quite rare that I *ever* use a declare block for anything
other than localizing exception handling.



  reply	other threads:[~2002-11-12 15:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-08  9:20 Let's change semantics of "use type" Victor Porton
2002-11-08 12:01 ` Adrian Hoe
2002-11-08 13:38 ` Robert A Duff
2002-11-08 20:52   ` Randy Brukardt
2002-11-08 18:12 ` Victor Porton
2002-11-09 15:20   ` Robert A Duff
2002-11-11  5:28 ` Victor Porton
2002-11-11 15:22   ` Robert A Duff
2002-11-11 15:59 ` Ted Dennison
2002-11-12  8:24   ` R. Tim Coslet
2002-11-12 15:39     ` Ted Dennison [this message]
2002-11-12 18:18       ` Preben Randhol
2002-11-12 17:29 ` Victor Porton
2002-11-12 17:32 ` Victor Porton
2002-11-18  1:25 ` Richard Riehle
2002-11-19  4:13 ` Victor Porton
replies disabled

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