TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Darin McBride
from: Mike Bilow
date: 1997-01-23 06:10:24
subject: writing REXX DLL`s

Darin McBride wrote in a message to Thomas Seeling:

 TS>  JdBP> if (!terminating) {
 TS>  JdBP> } else {

 TS> I don't think it is good style to handle both cases of 
 TS> a boolean decision and begin with the negated part. 
 TS> Probably the compiler can optimize it, but I wouldn't 
 TS> trust this :)

 TS> if (terminating) {}
 TS> else {}

 TS> is clearer, although your style fits the causality better :-)

 DM> Generally people try to put the error handling (and other
 DM> less-frequently run) code later.  "Terminating" is likely an
 DM> "error" (or at least not the normal path of execution), and
 DM> probably should be handled later.  OTOH, I prefer my
 DM> variables to be positive as well - rather than
 DM> "terminating," have "still_going" or
"alive" or even (if all
 DM> is lost), "not_terminating".  :-)  You win both ways - you
 DM> don't continually negate the variable, and you still get to
 DM> put the most-executed code first where we can read it
 DM> easier.  :-)

From a machine level point of view, you want branches to be not taken more
frequently than taken.  This is because taking a branch always flushes the
prefetch instruction queue in the Intel processors, and this can be a
severe speed penalty if the branch is inside a loop or some similarly
critical code.  A high level language compiler has no way to know whether
the programmer expects the branch to be taken or not, so optimization
cannot be depended upon to handle this.  The heuristic used by most
compilers in optimizing a branch is simply to decide which outcome
generates more code and assume that forward branches to larger code and
backward branches to shorter code will be taken more frequently, the idea
being that forward branches are usually exception tests and backward
branches are usually loops.

Unless you are in a truly critical area of the code, it is my opinion that
the paramount issue is source readability.  If you really need to worry
about this level of detail, you need a profiler and probably should be
working in assembly language in the first place.
 
-- Mike


--- 
* Origin: N1BEE BBS +1 401 944 8498 V.34/V.FC/V.32bis/HST16.8 (1:323/107)
SEEN-BY: 50/99 54/99 270/101 620/243 625/110 160 711/401 413 430 808 934
SEEN-BY: 712/311 407 505 506 517 623 624 704 713/317 800/1
@PATH: 323/107 396/1 270/101 712/624 711/934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.