Teams pick a coding convention...
- Together
- Per file
- Per language and framework
- To maximize readability
Click to show the answer
1 & 2 & 4: Teams should pick a convention they all find acceptable, based on the idioms of the language and framework they use, with the goal of making code easier to reason about. Choosing a different convention per file would work against that last goal.
A debugger can...
- Pause program execution for inspection
- Find bugs automatically in a program
- Modify program state regardless of "public"/"private" accessibility
- Work with only a compiled program
Click to show the answer
1 & 3 & 4: A debugger can inspect and modify all program state regardless of what visibility is specified in the source code, and does not strictly need source code or debugging symbols though these make the job much easier. However, debuggers do not perform analyses on their own..
A postcondition should be...
- Explicitly checked by callees
- Explicitly checked by callers
- A part of an invariant
- Used only alongside a precondition
Click to show the answer
None: A postcondition does not have to be explicitly checked at run-time, it could for instance be checked by static analysis tools or be too informal to be automatically verifiable. "The disk is not full after this method has been called, assuming nobody else touches the disk" is a valid postcondition, for instance. It may be used as part of an invariant, and may be used alongside a precondition, but it could also stand on its own.
One should defensively copy...
- All parameters
- All collections of items
- The
this
/self
object - Only in object-oriented languages
Click to show the answer
None: Defensive copying is necessary to avoid corrupting an object's inner state by accident or malice.
It is necessary when a function logically "takes ownership" of a value that is represented using a mutable type, such as List<Integer>
in Java.
This can also happen using mutable types in functional languages, but it may not happen even in object-oriented languages using immutable types.
One basic example of a type that never needs copying is int
.
Defensively copying the this
/self
object makes little sense.
Which of these can help debug?
- Invariants
- A debugger
- Logs
- Coding conventions
Click to show the answer
All of these can be useful, to various degrees, depending on the bug.