Software Specifications 101
Table of Contents
This is a "graduate level 101" intro to specs.
1 About Specifications
1.1 Spec Techniques
- Prescriptive/ Operational?
- Declarative Preferred
- Another Program as a spec of this one?
- English v Math + Logic
1.2 Specifications v Requirements
- mostly a question of points of view
- requ: POV of the clients/users
- spec: POV the designer/developer
- Should the Structure of Spec influence Design?
- Explicit admonition
1.3 Specifications meet Requirements
- Goal: Spec S meets requirements R: S \(\models\) R (S "models" R)
- How to verify? R is in English prose, S in some notations
- We seek consensus of humans readers: Give them S and R, and ask "What do you think? Are they the same?"
1.4 Different Axes of Specs
- Functional Specs
- Performance/ Resources Specs
- Maintainability
- A list of different specs by Hoare
1.5 Functional Specifications
- Input/Output relation
- Input = any thing the prg "reads" (depends on)
- Output =any thing the prg "writes" (generates)
1.6 Performance Specifications
- What and How-much is "consumed"?
- CPU time, memory, stack, heap, file space, …
- Big-Oh notations?
1.7 Robustness Specs
- Must not crash (no matter what the inputs are?)
- Must not hang
- Must not do "disastrous" operations
- (e.g., delete hundreds of files)
- unless undo/redo are available
1.8 Resource Specs
- PL used
- RAM, CPU, speed
- man hours
1.9 Miscellaneous Specifications
- PL-, IDE tools, … (to be used)
- Source code, documentation, … (to be produced)
- Software qualities expected [see Hoare's list]
2 Notations For Specs
- Discrete Math
- Mathematical Logic
- Functional Programming
- ../Assertions/math-logic.html
2.1 Formal or Informal?
- What is rigor? precision?
- Specification Languages
- Another Program as a spec of this one?
- Can every existing program be specified?
- Is every spec "mathematically" specifiable?
3 Seven Sins of a Specifier
- Noise The presence in the document of an element that does not carry information relevant to any feature of the problem. Variants: redundancy; remorse.
- Silence The existence of a feature of the problem that is not covered by any element of the document.
- Overspecification The presence in the document of an element that corresponds not to a feature of the problem but to features of a possible solution.
- Contradiction The presence in the document of two or more elements that define a feature of the system in an incompatible way.
3.1 Seven Sins of a Specifier #2
- Ambiguity The presence in the document of an element that makes it possible to interpret a feature of the problem in at least two different ways.
- Forward Reference The presence in the document of an element that uses features of the problem not defined until later in the document.
- Wishful Thinking The presence in the document of an element that defines a feature of the problem in such a way that a candidate solution cannot realistically be validated with respect to this feature.
- [cite Bertrand Meyer, see Refs; visit also http://deadlysins.com]
- Aren't these: Seven Sins of the Requirements Writer?
4 Correct wrt Assertions
- What is the notion of "correct" that you are using?
- It can never be a unary property. A program is correct with respect to (wrt) to something: another program, e.g.
- In this course it is never independent of its entry- and exit assertions.
4.1 Correct wrt Assertions: Vacuously
- If we give impossible to hold entry assertion,
- or if we give trivial to hold exit assertion,
- then any program will be correct with respect to those assertions.
4.2 Correct wrt Assertions: For-All
- There is an implicit for-all (symbol ∀) in the assertions.
- E.g., when we write n >= 0 in the entry assertions, it includes for all n that we may give so that n >= 0. The n that is bound here is taken in all subsequent assertions – in loop invariants and in the exit assertion.
4.3 Correct wrt Assertions: sorting-alg Example
- Our assertions for sorting:
{n >= 0} sorting-alg {sorted(a[0 .. n-1]) and permutation(a, a')}
5 Specs v Final Programs
- Expect that declarative specs are shorter than programs written in languages like Java or C++.
- Not always so. Consider the pseudo random number generators that
do
x = m*x + c
. The initial choice of x, m and c have an impact on the random number sequence. The specification of this sequence is considerably longer than the one liner implementation.
6 References
- Meyer, Bertrand, "On Formalism In Specifications", IEEE Software, 1985, vol. 2, no. 1. pp. 6-26. (Meyer is the designer of the excellent OOPL named Eiffel.) Required Reading.
- Others and Bertrand Meyer, "How Specifications Change and Why You Should Care", Jan 2013. Recommended Reading.
- Joel Spolsky, "Painless Functional Specifications - Part1. Why Bother?", 2000. "Painless Functional Specifications - Part 2: What's a Spec?" "Painless Functional Specifications - Part 3: But… How?" "Painless Functional Specifications - Part 4: Tips" (Spolsky is the designer and original builder of Stack Overflow.) Recommended Reading.