Design to fail fast and early

Design systems and processes that catch errors early, ideally at compile or test time rather than at runtime. Implement strict type checks and use automated testing to catch potential issues before code even reaches production. If there's a situation you think should never happen, but the types suggest that it is in fact possible, rather than glazing over the type warnings, add code to handle that case and throw an error with a useful error message indicating that things are in an unusual state.

Examples

  • You're working on a user submitted form, and instead of validating data only at the database level, you add validation rules directly in your form. For example, fields like 'email' or 'password' are validated on the client side before submission. This catches errors early, reducing back-and-forth with the server.
  • You're integrating with a third party HTTP API. Instead of ignoring type errors, you add parsing of their responses and error out with a useful error message if something is unexpected.