Both of these approaches aim to record the programmers’ expectations about what code is doing. The most immediate effect of this is that the programmer has to actually consider and make precise what those expectations are; after that, making them explicit means that others can read, understand, and possibly challenge them. All this can happen without a formal annotation language or machine assistance. However, once we do use a precise language, it becomes possible to automatically check whether a program does meet the given specification.
There are many different routes to such checks. The
assert statement in Java tests that running code behaves as expected. The more extensive JML framework uses a single Hoare-like annotation language to support many different kinds of check: automatic insertion of appropriate
assert statements; machine-generated tests; static checking of properties at compile-time; and more.
In all of these we are expanding the language not to write programs with a wider range of behaviours or effects, but to write programs that have the correct behaviours or effects for the task they are to perform.
Link: Slides for Lecture 12
JML is just one of many frameworks for specifying and verifying code. Other examples include Java annotations, FindBugs™, QuickCheck, the C specification language ACSL and the Frama-C platform, Spec#, and many more. Your homework is to find out about one particular such system.
On assertions in Java and ways to use them.
|Oracle Java Technology Network
Programming with Assertions
Oracle language technical note for Java 8 describing what assertions are and illustrating different ways of using them.
When to Use an Assertion and When to Use an Exception
“Most of the time I will use an exception to check for a condition in my code, I wonder when it is an appropriate time to use an assertion?”
On the Liskov substitution principle.
ACM Turing Award 2008
For contributions to practical and theoretical foundations of programming language and system design, especially related to data abstraction, fault tolerance, and distributed computing.
Link: ACM Turing Award Citation
Corporate Vice-President, Microsoft Research
Previously head of the Department of Computer Science at Carnegie Mellon University and assistant director of the US National Science Foundation. Strong advocate for computational thinking across multiple disciplines.
Links: Wing at Microsoft; Computational Thinking
|A Behavioral Notion of Subtyping
Barbara Liskov and Jeanette Wing
ACM Transactions on Programming Languages and Systems 16(6):1811–1841
Links: Access through Edinburgh University Library (may require EASE login); Publisher’s page