comp.lang.ada
 help / color / mirror / Atom feed
From: Wes Groleau <wwgrol@ftw.rsc.raytheon.com>
Subject: Re: short-circuit control forms (& 'long names are doom')
Date: Fri, 22 Jun 2001 10:46:12 -0500
Date: 2001-06-22T10:46:12-05:00	[thread overview]
Message-ID: <3B336844.9B58ED9A@ftw.rsc.raytheon.com> (raw)
In-Reply-To: QGyY6.222270$p33.4459972@news1.sttls1.wa.home.com


> There was an interesting thread on this subject back in 95 (search for short
> circuit in the Google archives of comp.lang.ada).

Didn't work.  Seeral search methods only returned parts
of this (current) thread.

> I found Tucker Taft's comment particularly interesting:
> 
> ": If both operands are
>  : always evaluated, does that mean that whenever it is unnecessary to
>  : evaluate the second operand, one should use the short-circuit operators
>  : for efficiency?

I hope he's listening, because without seeing the whole post,
I strongly suspect that his answer was "no"

>  To avoid depending on the quality of your compiler's optimizer,
>  I personally recommend using short-circuit operations by default,
>  and only use "and" or "or" when it is *required* that both
>  operands be evaluated.

I do not recommend "depending on" the optimizer, but
I recommend even more strongly NOT disabling the optimizer.

>  Hence, if your compiler is clever, it doesn't matter what you
>  do since it will un-do it if appropriate, and if your compiler is

If  _allowed_  and appropriate.

>  not clever, then using short-circuit by default probably produces
>  somewhat better code quality on average.

For reasons already stated in this thread, I doubt it.  That's if
you define "code quality" as "efficient."  If you define it as clear,
readable, and less error-prone, then for reasons already stated
in this thread, I doubt it.

What surprises me the most about our "profession" in general
is the fact that the folks "in the trenches" habitually ignore
the good advice of the "experts" that we claim to respect.

Since nearly THIRTY YEARS AGO (and probably longer), folks have
known and written of the foolishness of misguided "optimization"
efforts (emphasis mine):

   Kernighan & Plauger, 1974.  Elements of Programming Style:

     Make it right _before_ you make it faster.

     _Keep_it_right_ when you make it faster.

     Make it clear _before_ you make it faster.

     Don't sacrifice _clarity_ for small gains in "efficiency."

     Let your _compiler_ do the simple optimizations.

     Keep it _simple_ to make it faster.
        [I have fixed at least as many bugs by
         _removing_ code as I have by adding code. -WWG]

     Don't diddle code to make it faster � find a better algorithm.

     Instrument your programs.  _Measure_ before making "efficiency" changes.

   Ledgard, Nagin, Hueras, 1979.
   Pascal with Style: Programming Proverbs:

     Shortening the code, running the program faster,
     or using fewer variables are all popular pastimes. .....
     Not mentioning ... the extra testing time needed
     to check the new and often subtle boundary conditions,
     are you _sure_ that fewer machine instructions or
     faster machine execution is likely?

   Some others which I have not been able to verify the sources of:

     Rules of Optimization:
     Rule 1: Don't do it.
     Rule 2 (for experts only): Don't do it yet.
        - M.A. Jackson

     "More computing sins are committed in the name of efficiency
     (without necessarily achieving it) than for any other single
     reason - including blind stupidity."
        - W.A. Wulf

     "We should forget about small efficiencies, say about 97% of
     the time: premature optimization is the root of all evil."
        - Donald Knuth

-- 
Wes Groleau
http://freepages.rootsweb.com/~wgroleau



  reply	other threads:[~2001-06-22 15:46 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-20 19:23 short-circuit control forms James A. Krzyzanowski
2001-06-20 20:15 ` Ted Dennison
2001-06-20 20:47 ` Marin David Condic
2001-06-20 22:23 ` Jeffrey Carter
2001-06-21  0:45   ` Al Christians
2001-06-21 15:06     ` Wes Groleau
2001-06-21 15:46       ` Al Christians
2001-06-21 18:28         ` Wes Groleau
2001-06-21 18:51         ` Marin David Condic
2001-06-22 12:17           ` Marc A. Criley
2001-06-22 14:55             ` Marin David Condic
2001-06-22 20:58   ` Robert Dewar
2001-06-22 21:49     ` Ted Dennison
2001-06-22 22:58     ` Jeffrey Carter
2001-06-23  0:38       ` Larry Kilgallen
2001-06-23 17:34       ` Simon Wright
2001-06-26 15:48       ` Wes Groleau
2001-06-25 17:00     ` Wes Groleau
2001-06-21  0:13 ` Mark Lundquist
2001-06-21  0:55   ` Al Christians
2001-06-21 12:39   ` Larry Kilgallen
2001-06-21 15:02   ` Wes Groleau
2001-06-21 14:24 ` short-circuit control forms (& 'long names are doom') Paul Graham
2001-06-21 17:20   ` Warren W. Gay VE3WWG
2001-06-21 18:32     ` Wes Groleau
2001-06-21 23:18   ` Charles Hixson
2001-06-22  1:01     ` Larry Kilgallen
2001-06-22  3:10     ` DuckE
2001-06-22 15:46       ` Wes Groleau [this message]
2001-06-22 19:02         ` Ted Dennison
2001-06-22 19:16         ` Ted Dennison
2001-06-22 20:53         ` Robert Dewar
2001-06-22 20:43       ` Robert Dewar
2001-06-22 22:34         ` Jerry Petrey
2001-06-25 14:30         ` Marin David Condic
replies disabled

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