Whiley, a programming language with extended static checking
whiley.org
whiley.org
So, what do you think would be better than "~="? (that's a genuine question since the syntax is not locked down yet by any means). I thought about "isa", also "<:" (following academic papers) and, of course, plain old "instanceof". But, the latter is too much finger typing for me ...
Oh, and of course we could do something like "typeof(x) == int" etc
switch x := node.(type) {
case Node:
// x is of type Node in this block
case Leaf:
// x is of type Leaf in this block
}
(http://golang.org/doc/go_spec.html#Type_switches)I'm guessing that for more complex things ('name' field of record does not already exist in the database) that you'll have to program them the old-fashioned way anyhow. Which leaves you code a mix of the 2 ways.
And really, wouldn't this be just as good and concise?
throw "Y can't be zero" if y == 0
There is a fair bit of theory about static verification/analysis of programs, a lot of which is applied in optimizing compilers as well. I'm not familiar with it, but I imagine that in this case it just fails on anything less than positive proof, and is comfortable with the strict standard that imposes.
It talks more about constraints here: http://whiley.org/guide/constraints/ .
This is similar to the behavior of array accesses in Java: If you access an invalid index the JVM is required to throw an out of bounds exception. In practice this would be unacceptably slow and if the compiler can prove that such an exception can never happen, the check will be removed.
As for the "simple" example of testing "y == 0", this is actually already undecidable. If you are interested, you might have a look at Nielson's "Principles of Program Analysis", I think that this particular example (undecidability of MOP Constant Propagation) is worked out there. Also, the book is a nice introduction to the subject.