RSSAmplifier

Steven Kalt · Nov 5, 2019

Parse, don’t validate

0
Sign in to vote or save

This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.

TL;DR: parsers take less-structured data and try to turn it into more-structured data. They don’t always succeed, so all parsers need to handle failure. validating throw s away information as exceptions/errors, while parsing holds onto that information parsing inputs as early as possible helps you trust the validity of data once it reaches your business logic. Beware of “shotgun…

TL;DR:

  • parsers take less-structured data and try to turn it into more-structured data. They don’t always succeed, so all parsers need to handle failure.
  • validating throws away information as exceptions/errors, while parsing holds onto that information
  • parsing inputs as early as possible helps you trust the validity of data once it reaches your business logic.
  • Beware of “shotgun parsing”: validation checks scattered throughout a codebase. “Shotgun parsing necessarily deprives the program of the ability to reject invalid input instead of processing it.”

Or, more succinctly,

Read on /notes/techniques/parse_dont_validate/

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.