[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sieve & short-circuit evaluation



Tim Showalter wrote:

> Today a bunch of us got together by the pool to discuss whether or not
> Sieve should have short-circut evalation.  After some arguing, we
> concluded that it shouldn't, and that extensions that made use of it
> were just a bad idea.
>
> One note, though.  While I still believe this is the right conclusion,
> this is the mechanism that some languages (C, LISP) use to return an
> exceptional condition (disk full, network exploded, etc.).
>
> This means that if we get a complex extension that can fail when it is
> run AND we have enough of a language for a fallback condition, we'll
> have to provide a way to handle what amounts to an exception.

I may be stating the obvious here, but don't forget that short circuit
conditionals can always be rewritten using nested if statements. It's a
straight forward conversion. Unfortunately, else clauses after such a
conditional need to be duplicated to get equivalent functionality:

This:
    if extension_that_can_fail() && something_else() {
        # this requires short circuit evaluation
    }
becomes:
    if extension_that_can_fail() {
        if something_else() {
            # nested if is equivalent to short circuit evaluation
        }
    }

And this:
    if extension_that_can_fail() && something_else() {
        # this requires short circuit evaluation
    }else {
       some_more_code();
    }
becomes:
    if extension_that_can_fail() {
        if something_else() {
            # nested if is equivalent to short circuit evaluation
        }else {
           some_more_code();
        }
    }else {
       some_more_code();
   }

    Tony Hansen
    tony@xxxxxxx