comp.lang.ada
 help / color / mirror / Atom feed
From: Richard D Riehle <laoXhai@ix.netcom.com>
Subject: Re: Software landmines (was: Why C++ is successful)
Date: 1998/09/01
Date: 1998-09-01T08:04:51-07:00	[thread overview]
Message-ID: <6sh2ej$o9e@sjx-ixn1.ix.netcom.com> (raw)
In-Reply-To: 35eca5d9.4354839@news.geccs.gecm.com

Brian,

Silly indeed!  I do not appreciate your use of the pejorative "silly"
in response to my postingsince it seems to be a deliberate insult. I do
admit that my hastily composed example could have been coded with more
clarity. It did not occur to me that I would need to submit a perfect code
example to make such a simple point but, since martinets abound, I submit a
new, probably unnecessary, example.  In case you have missed my original
point in your zeal to criticize the code fragment, it is as follows: Ada is
designed to encourage use of the assignment statement if we also want our
code to be clear and readable.  This was in response to Robert's (correct)
assertion that programmers use assignment statements too liberally.     

I am appending your code example and mine in case some masochist wants to
read it.  I hope you understand that my example was not intended to
represent real code.  Perhaps the way I wrote the assignment statement
confused you regarding my intentions.  I concur that, if there is a simple
algorithm, it can be stated as part of the declaration.  In the kind of
function I had in mind, there could be multiple possible values for the
Result.  In this case, the choice is between,

       Example (1)
         function F1 (paramter-list) return Result-type is
             Result : Result-type := initial-value;
         begin
           if condition-1 then
              Result := result-1;
           elsif condition-2 then
              Result := result-2;
           else
              Result := result-3;
           end if;
           return Result;
         end F1;

    versus Example(2)

         function F2 (paramter-list) return Result-type is
         begin
           if condition-1 then
              return result-1;
           elsif condition-2 then
              return result-2;
           else
              return result-3;
           end if;
           return Result;
         end F2;

The two (simplified) functions epitomize the debate about a particular
coding style. Example(2) illustrates how functions avoid using an
extraneous assignment statement.  Some practitioners prefer Example(1).
I use both in my coding. It depends on the complexity of the function,
my audience (everyone on the project is an ex-Fortranner), along with
several helpings of intuition.  Over the years I have found that 
Example(1) has been less error-prone and easier for the average programmer
to maintain.  Your mileage may vary according your experience.

-- ==================== Original Postings ====================
-- What follows is my original message along with Mr. Orpin's 
-- rather impolite reply.  
-- ===========================================================


In article <35eca5d9.4354839@news.geccs.gecm.com>,
	abuse@borpin.demon.co.uk (Brian Orpin) wrote:

in response to the following code fragment submitted by me,

>On Mon, 24 Aug 1998 19:47:31 GMT, Richard D Riehle
><laoXhai@ix.netcom.com> wrote:
>
>> Don't take away my assignment statements, Robert.  The help me write
>> crisp, short code sentences that ordinary mortals can understand. In
>> fact, as an old time Fortranner, I sometimes write a function that
>> looks like,
>
>>       function F ( ... ) return some-data-type is
>>         Result : some-data-type := initial-value;
>>       begin
>>         Result := algorithmic-part;
>>         return Result;
>>       end F;
>
>Which of course is pretty silly <g>.  Result has a default value that is
>never used.  Could easily be written..
>
>function F ( ... ) return some-data-type is
>	Result : some-data-type := algorithmic-part;
>begin
>	return Result;
>end F;
>
>or even 
>
>function F ( ... ) return some-data-type is
>begin
>	return algorithmic-part;
>end F;
>
>YMMV

 




  parent reply	other threads:[~1998-09-01  0:00 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-08-22  0:00 Software landmines (was: Why C++ is successful) dewar
1998-08-23  0:00 ` Dale Stanbrough
1998-08-23  0:00   ` dewar
1998-08-23  0:00   ` Andi Kleen
1998-08-24  0:00 ` Richard D Riehle
1998-08-25  0:00   ` Andi Kleen
1998-08-25  0:00     ` Brian Rogoff
1998-08-25  0:00   ` dennison
1998-08-28  0:00   ` Matthew Heaney
1998-08-28  0:00     ` Richard D Riehle
1998-08-29  0:00       ` Matthew Heaney
1998-08-29  0:00       ` Matthew Heaney
1998-09-06  0:00         ` John G. Volan
1998-09-07  0:00           ` Mats Weber
1998-09-07  0:00             ` dewarr
1998-09-08  0:00               ` Tucker Taft
1998-09-08  0:00                 ` Precalculation of parameters (was: Software landmines) dennison
1998-09-09  0:00                   ` Tucker Taft
1998-09-09  0:00                     ` dennison
1998-09-10  0:00                       ` Tucker Taft
1998-09-10  0:00                         ` dewarr
1998-09-16  0:00               ` Software landmines (was: Why C++ is successful) Matthew Heaney
     [not found]   ` <35eca5d9.4354839@news.geccs.gecm.com>
1998-09-01  0:00     ` Richard D Riehle [this message]
  -- strict thread matches above, loose matches on Subject: below --
1998-08-06  0:00 Why C++ is successful Robert Dewar
1998-08-07  0:00 ` harald.mueller
1998-08-07  0:00   ` Brian Rogoff
1998-08-07  0:00     ` Timothy Welch
1998-08-08  0:00       ` Robert Dewar
1998-08-08  0:00         ` Jeffrey C. Dege
1998-08-10  0:00           ` Laurent GUERBY
1998-08-12  0:00             ` Andy Ward
1998-08-14  0:00               ` Robert Dewar
1998-08-14  0:00                 ` Software landmines (was: Why C++ is successful) dennison
1998-08-15  0:00                   ` Thaddeus L. Olczyk
1998-08-16  0:00                   ` Robert Dewar
1998-08-17  0:00                     ` dennison
1998-08-18  0:00                       ` adam
1998-08-19  0:00                         ` Tucker Taft
1998-08-19  0:00                           ` adam
1998-08-19  0:00                       ` ell
1998-08-19  0:00                         ` Charles Hixson
1998-08-19  0:00                         ` adam
1998-08-19  0:00                           ` Dan Higdon
1998-08-20  0:00                             ` adam
1998-08-20  0:00                               ` Dan Higdon
     [not found]                               ` <m33eagru5g.fsf@mheaney.ni.net>
1998-08-31  0:00                                 ` Frank Adrian
1998-08-31  0:00                                   ` Robert I. Eachus
1998-08-31  0:00                                     ` Biju Thomas
1998-08-31  0:00                                       ` Robert Martin
1998-09-01  0:00                                         ` Martin Dowie
1998-09-01  0:00                                       ` Robert I. Eachus
1998-09-02  0:00                                         ` dennison
1998-09-01  0:00                                   ` dewarr
1998-09-06  0:00                                 ` Jonathan Guthrie
1998-08-20  0:00                           ` Ell
1998-08-21  0:00                             ` Ell
1998-08-21  0:00                               ` Larry Brasfield
1998-08-21  0:00                                 ` Ell
1998-08-21  0:00                                 ` Jeffrey C. Dege
1998-08-20  0:00                                   ` Phlip
1998-08-21  0:00                                   ` Larry Brasfield
     [not found]                                   ` <DOSXjHE9T6DM9Jw9nAyaPxfz@news.rdc1.bc.wave.home.com>
1998-08-22  0:00                                     ` dewar
1998-08-24  0:00                                       ` Martin Dowie
1998-08-24  0:00                                         ` Martin Dowie
1998-08-24  0:00                                           ` Mark A Biggar
1998-08-25  0:00                                             ` Martin Dowie
1998-08-25  0:00                                               ` Mark A Biggar
1998-08-26  0:00                                                 ` Martin Dowie
1998-08-25  0:00                                         ` adam
1998-08-24  0:00                                       ` dennison
1998-08-28  0:00                                         ` Matthew Heaney
1998-08-28  0:00                                           ` dennison
1998-08-30  0:00                                             ` Matthew Heaney
1998-09-06  0:00                                               ` John G. Volan
1998-08-31  0:00                                             ` Robert I. Eachus
1998-09-22  0:00                                       ` Charles H. Sampson
1998-08-21  0:00                                 ` Bob Collins
1998-08-21  0:00                               ` John Goodsen
1998-08-21  0:00                                 ` Ell
1998-08-21  0:00                                   ` Ell
1998-08-20  0:00                         ` Gerry Quinn
1998-08-16  0:00                   ` Jay Martin
1998-08-17  0:00                     ` Robert Dewar
replies disabled

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