02 Abstraction and Specification¶
It's been said that computer science is the study of abstractions, but what is an abstraction?
ab·strac·tion (from middle french & late latin)
verb: abstract
- Forgetting information, so that different things can be treated the same
noun
- Artifacts that result from that process.
When creating abstractions, one important part is writing specifications for them.
spec·i·fi·ca·tion (unknown etymology)
noun
- intended behavior of abstraction
verb: specify
- The act of creating such an artifact (creating a specification)
Audiences of specifications¶
The different audiences have different specifications
Clients¶
- What they must guarantee (preconditions)
- What they can assume (postconditions)
Implementers¶
- What they can assume (preconditions)
- What they must guarantee (postconditions)
Benifits of specifications¶
- Locality: understand abstraction without needing to understand implementation
- Modifiability: change implementation without breaking client code
- Accountability: clarify who is to blame when something goes wrong
Satisfaction¶
An implementation satisfies a specification if it provides the described behavior.
Many implementations can satisfy the same specification
- Client must assume it could be any of them
- Implemented gets to pick one
(everyone should act in good faith)
Ambiguity¶
These factors may create ambiguity, which decrases satisfaction
- The client didn't understand what they wanted you to implement
- The client genuinely didn't care
- You didn't understand the meaning
These can all lead to ambiguity in a specification.
How do we avoid this?
- If you wrote the specification, improve it!
- If the client wrote the specification, seek clarification (but don't make 500 clarifications lol)