Defensive programming is explored through a practical example of parsing a time string in Swift. Starting from a naive implementation that crashes on bad input, the post walks through progressively more robust approaches: nil checks, logging warnings, providing default fallback values, and even correcting corrupted data on the fly. A decision framework is provided to help developers choose the right level of defensiveness based on factors like data reliability, system criticality, release cadence, and test coverage.

8m read timeFrom marcgg.com
Post cover image
Table of contents
The exampleAvoiding crashesHow defensive should one be?

Sort: