Hasty Briefsbeta

A programmer's field guide to assertions

7 days ago
  • #programming
  • #software-development
  • #assertions
  • Assertions in code verify conditions at specific points, interrupting normal flow if false.
  • Common responses to tripped assertions include exceptions, panics, or program termination.
  • Assertions can be conditional based on build configuration: Debug (development only) or Production (all builds).
  • Assertions complement other robust software techniques like testing and type invariants.
  • The post shares practical examples of assertion use, including monotonic map construction and database query scanning.
  • Effective assertion use requires confidence in the asserted conditions and avoiding assertions about external systems.
  • Organizational adoption of assertions involves addressing cultural and technical objections.
  • Common objections include performance overhead, code readability, and risk of production failures.
  • Assertions should be paired with coarse-grained recovery mechanisms in online systems.
  • The post concludes with encouragement to explore assertions in open-source projects for deeper understanding.