Defect Attractors
notes date: 2018-10-24
source links:
source date: 2018-05-30
- In studying error statistics of large C++ programs, Les Hatton described class inheritance as a defect attractor.
- A “defect attractor” of a program, language, API, or any other kind of software construct is a feature which, while possibly not bad in itself, spawns defects in the design or code near it.
- The concept unifies a large class of things experienced software engineers know are problems. Portability and backward-compatibility shims are defect attractors. Global variables are defect attractors. Special, corner, and edge cases are defect attractors – in fact, when we complain about something being a special case we are usually expressing unease about it being a defect attractor. “Special case” is the what of our complaint, defect attractor is the why.
- Class inheritance
- spawns questions like how to handle diamond inheritance that don’t have one good answer but multiple bad ones
- endianness-sensitive data representations, binary wire and file formats in general, and floating point
- In C: pointer arithmetic. Casts. Unions and type punning. And of course the Godzilla of defect attractors, manual management of dynamic memory allocation
- In any language, the goto statement is a famous defect attractor. So are text-substitution macros in languages that have anything resembling a preprocessing stage.