For Thursday 1 Oct 2015, read:
Effective use of assertions in C++,
Mike A. Marin,
ACM SIGPLAN Notices,
Volume 31 Issue 11, Nov. 1996,
Pages 28-32. and answer the following reaction questions:
[note: ## is the C preprocessor's concatenation operator, see
wikipedia entry on C preprocessor.]
- What is the difference in effectiveness of class invariants
if your class has public fields rather than keeping all fields
- In mutation testing, we can generate mutants that go into an
infinite loop. If we could keep the mutation from messing up the
assert code, what type of invariant would be guarenteed to abort the
program if it was headed into an infinite loop? Why?
- In the factorial example on page 30 (see page numbers at bottom of page),
why is the expression n-i being used as the second parameter to the LoopVariant
macro rather than the expression i?
If you have forgotten about loop invariants or they weren't covered in your
CS logic course, there is a reasonable wikipedia entry on loop invariants. Wikipedia also has an
entry on the less commonly referred to loop variant. Also, CS logic course don't usually talk
about class invariants, but there is a wikipedia entry on that too.
Basically, they are all
assertions. It is just useful to be able to distinguish different kinds of
assertions. For loops, you want to remember to check each time around the loop
to make sure it is doing the right thing (loop invariant). Also it is useful
to check that the loop is making orderly progress toward coming to an end
(loop variant). And, it is useful to check to make sure that their different
parts of an object are consistant with the definition of the object (for example
at the start and end of various methods), the class invariant. The point of
the paper is to show how you can set up special macros to handle this in C
and C++ and how you go about using such macros.
Since Java doesn't have macros, the implementation of these types of invariants
(as opposed to just using a bunch of asserts), would involve a non-standard
package called JML ( yes it too has a wikipedia entry). This turns out to be more complicated
that one would like because one needs a version of JML that matches the version
of Java you are using. While you can't use C's preprocessor with Java as
it tries to parse the input program, it turns out you can use the m4 preprocessor with Java (by first running the source code through m4 and then taking the
result and handing it to javac) -- so it might be possible to get a set of macros
that can sort of work with Java along the lines of the C/C++ macros described
in thsi article.
- NOT MATERIAL FOR EXAM OR QUIZZES:
Assertions: a personal perspective,
Annals of the History of Computing, IEEE (Volume:25 , Issue: 2 ),
Page(s): 14 - 25.
Assert early and assert often: Practical hints on effective asserting,
Tony Hoare, TechFest, Feb 2002. [observes that about a quarter million asserts
were used in Microsoft Office.] this document is 24 slides, with a paragraph
of detail under each slide recording a talk he gave.
A historical perspective on runtime assertion checking in software development,
Lori A. Clarke and David S. Rosenblum,
ACM SIGSOFT Software Engineering Notes,
Volume 31 Issue 3, May 2006,
- The Oracle Problem in Software Testing: A Survey
Barr, E.T. ,
Harman, M., McMinn, P., Shahbaz, M., Shin Yoo,
Software Engineering, IEEE Transactions on (Volume:41 , Issue: 5 ),
Page(s): 507 - 525.
On Testing Non-Testable Programs
Elaine J. Weyuker,
Computer Journal Volume 25, Issue 4, 1982, pp. 465-470.
- wikipedia entry for
C's assert.h header file which defines the macro assert for including
assertions in C code (that can also be turned off with compiler options).
documentation for C++'s cassert include mimics C's assert.h
- Programming with Assertions, Oracle's guide to using Java's
assert statement (version 1.7 Java).
Python's assert facility
Assert Use in GitHub Projects
C Casalnuovo, P Devanbu, A Oliveira, V Filkov, and B Ray, cs.ucdavis.edu.