L4: Improving Software Quality by Design Flashcards
What are software bugs?
Errors in design, development, or operation causing unexpected behaviour / results.
How do bugs happen?
- Programmer creates a defect
- Defect causes an infection
- Infect propagates
- Infection causes failure
How to deal with bugs?
Improve software quality by:
- Properly designing the system
- Quality assuring the code
- Testing the system
- Debugging failures
What might lead to bugs in the design process? What about in the software design?
The design process:
- Misunderstanding a customer
- Misinterpreting a written requirement
- Overlooking a case when analysing requirements
The software design:
- Adopting an incorrect algorithm
- Making an unwarranted asssumption about the code
- Making a typing error when entering code
- Implementing incompatible interfaces
What is the definition of robustness?
Ability of a system to cope with errors and erroneous input
Why do we need robustness and contracts?
- Making developers aware of problematic execution cases
- Avoiding such problematic cases from the start
- Defining where to put blame:
1. No explicit signaling for violated preconditions implemented
2. Explicit signaling for violated precodintions implemented
How to improve the code and make it more robust?
- Using JavaDoc and natural language
- Parameters:
1. Definition of the parameters a method receives
2. Helpful to specify variables more precisely and to add expected units - Precondition:
1. Must be true before execution
2. Can be imposed on state of class, arguments passed, …
3. Impose obligations on the client - Postcondition:
1. Must be true after execution
2. Can be imposed on state of class, return type, values, …
3. Impose obligations on the method
Writing contracts
Idea of design by contract:
- Formal and verifiable specification
- Supported by some programming languages
- Including preconditions, postconditions, and invariants
For this course:
- @param, @pre, @post, @return, @throws
- Be as precise as possible
- Not fully formal
What happens at an exception?
- It will terminate the program execution by returning the defined exception
- A method is robuts if it always throws an exception if its preconditions are violated
- The returned exception must be handled by the client
When to use exceptions?
- Make a method robust
- Avoid encoding information in special values
- Signal special (erroneous) situations in non-local (non-private) methods
- Ensure that a failure cannot be ignored
White-box and black-box testing
White-box: test internal logic
- Consider only the code, ignore specification
- Used to test internal state of the system
Black-box: test intended functionality
- Consider only specification and requirements, ignore code
- Used to test correct behaviour
Test-driven development
Core Idea:
- Develop tests first to specify new behaviour
- Develop code to fulfill tests
- Improve code quality