Bifalgorithm post · Computer science one · Enumerated Types
Why are enumerated types better than arbitrary integer error codes?
Why are enumerated types better than arbitrary integer error codes? (Computer science one · Enumerated Types) — "The usage of the integers 1, 2, 3 to indicate…
Ideas in this flowchart
- Error codes should use human-readable identifiers instead of arbitrary integers.
- Using 1, 2, and 3 for different errors is arbitrary.
- The integers are magic numbers whose meanings are not apparent.
- Calling functions must compare returned values with various integers.
- Users must repeatedly consult documentation to match each integer to an error condition.
- The errno strategy defines human-readable identifiers for each error code.
- Macros can be used to define the human-readable error identifiers.
- An enumerated type provides another solution.