1. Re: Short Circuiting
- Posted by David Cuny <dcuny at LANSET.COM>
Jun 23, 1998
-
Last edited Jun 24, 1998
Isaac suggested something along the lines of (I'm paraphrasing):
> try:
> if length( s ) > 2 then
> if compare( s[1..3], "EOF" ) = 0 then
> ... [alpha]
> else
> ... [beta]
> end if
> else
> [gamma]
> end if
The problem with his example is that I'm stuck at [beta] when I want to be at
[gamma]. That's part of my complaint.
Joe Phillips responded:
> To get the above code to work, you could create a function into which
> you send s. This would provide a single point of logic that would
> allow a simple if-then-else structure as you desire. (Although
> a short-circuit logic would be cleaner)
Which was essentially what the remainder of my e-mail was trying to say.
I am NOT in favor of short circuiting.
On the other hand, tests on slices are inherently UNSAFE. You have to test the
range before you can safely test the slice - leading to some very ugly. It is
at this point that short curcuit logic begins to be very appealing.
I again suggest that perhaps Robert include some routines for newbies, and
sloppy coders like me. Error that I continually fall prey to are:
1. Always: Forgetting the '=0' at the end of compare.
2. Often: Testing slices where are outside of range.
These types of errors initially caused me great frustration with Euphoria,
until I wrote my own support functions that made the operations safer. I think
that a collection of these sorts of routines might be useful.
Then again, it wouldn't be the first time I was wrong,
-- David Cuny