On Mon, Apr 25, 2016 at 4:13 PM, Christopher Schultz <
ch...@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Leon,
>
> On 4/22/16 12:24 PM, Leon Rosenberg wrote:
> > Hi guys,
> >
>
> I would always choose the case with the elses.
>
> First, I think it's more clear: if you expect that only one branch of
> the code will run, and no others, then the elses tell the reader that
> fact without any further commentary. The zero-else case might help you
> catch some logic errors (because for example you can log each entry
> into a branch) but there are of course other ways to do that.
>
> Second, it's more efficient, regardless of what type of processor you
> have. Let's take an example where there are more than 3 branches. How
> about something like a million branches (just to accentuate the
> point)? If one of the branches runs, the others are skipped. If all
> branches have an equal change of being chosen, then the CPU has to
> perform on average 500000 predicates. If you put the common cases at
> the top, you can do even better. Let's assume the 80/20 rule applies,
> here, and you can take a guess that, on average, the CPU will only
> have to perform 100000 predicates on average.
>

I don't think the example is valid (even if machines with 100.000 cpus and
more actually exist). But I remember from days of my study, which lies way
way back, that languages that are optimized for parallel processing would
be able to tell the compiler to execute all ifs in parallel. So if we stick
with a number of ifs which is less than the number of available cores/pipes
we could run it all in parallel. I don't think it is possible with if else,
unless it is transformed into something else.

The other thing that made me wonder is that most people on the list (or all
except me) actually considered if-else-if-else more readable. It not only
creates a more complex structure (visually and syntactically  (more
letters)). But also the semantics of an *else* are different as of an *if*.
This is like North Carolina ;-)
if (man){ do_man_thing; } else { do_woman_thing(); } doesn't work anymore,
even it worked 20 years ago. Talking about maintaining :-)

regards
Leon

>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iEYEARECAAYFAlceJg8ACgkQ9CaO5/Lv0PAODQCfRCBvVgM2HSM2/CBEGtlBe0Pg
> MrcAn2OdBYKJR0OSApcBFfONJHOlKGY0
> =YeMH
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

Reply via email to