On Sun, 17 Aug 1997, David Klasinc wrote:
> Now something about the coding... What will run faster a bunch of if's or
>switch? :)
Completely and totally irrelevant. :-) If there is one thing I have
ever learned about programming, it's that coders' time is much more
valuable and scarce than computers' time; so, always write the code
that is *clearest*. The exception comes if you are 1) writing a
program which needs to be highly optimized (e.g., has been
quantitatively shown to be using too much CPU time or wall-clock
time), and 2) you have used a tool like gprof to quantititatively show
that the bottleneck in your program is the if/elseif or case/switch
logic.
I'm very embarassed that I used to write, for example, "damage >>= 2"
instead of "damage /= 4", in the name of "efficiency". What a crock.
Even assuming I had a brain-dead compiler that didn't automatically do
that conversion for me (most do), saving 5 clock cycles in the middle
of a spell damage calculation is the most idiotic and irrelevant
optimization possible -- probably a 0.000001% savings in the overall
time it takes to make a single pass through game_loop(), and
*definitely* not worth the confusion that it causes for some newbie
coder who doesn't know what ">>=" means.
So, my advice in a nutshell: unless you have some compelling reason
not to, write whatever is clearest, leading to the fewest bugs
and the least confusion when future coders (both you and others) read
it.
+------------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
| http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
+------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/08/00 PST