[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sqlite-users
Subject:    Re: [sqlite] MC/DC coverage explained wrong in the home page?
From:       Darren Duncan <darren () darrenduncan ! net>
Date:       2011-09-23 22:30:54
Message-ID: 4E7D089E.6070901 () darrenduncan ! net
[Download RAW message or body]

Richard Hipp wrote:
> Opinions vary on the exact meaning of MC/DC for a language (such as C) that
> has short-circuit boolean operators.
<snip>
> There are problems with this view, though.  In many instances, B is
> undefined when A is false.  In other words, if A is false, any attempt to
> calculate B will give undefined results - possibly a segfault.  SQLite
> really does use the fact that && is a short-circuit operator in C and so
> when A is false, it is technically illegal to make any conjectures about the
> value of B.
<snip>
> Your objections would be understandable if SQLite where written in Pascal or
> Ada where AND and OR operators are not short-circuit and where the compiler
> is free to reorder them if it sees fit.  But in C/C++ where the && and ||
> operators are short-circuit, and where the tests must occur in a
> well-defined order, things are different.  It is as if the && and ||
> operators really marked boundaries between decisions, not conditions.
> 
> But the | and & operators used inside a decision are *not* short-circuit,
> and in those cases, your objections are valid.
<snip>

This is why I think it is valuable for a programming language to provide 
multiple versions of some operations such as boolean "and","or" where one 
variant doesn't short-circuit and the other does.

The primary purpose, then, of short-circuiting operators, is *not* about 
performance but rather about validity; they would be used in situations where 
the value of one operand determines whether it is even valid to calculate the 
other operand, such as if the first operand is a type check and the second is an 
operation that is only valid for some types.

In fact, for a computationally complete language that is functional, I would 
argue that short-circuiting logic operators is essential.

The non-short-circuiting boolean operators would be for all other uses, where 
the validity of one argument doesn't depend on the values of any of the other 
arguments, and so the compiler can be free to reorder it.

-- Darren Duncan

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic