Parse, don’t validate


49 bookmarks. First posted by niklasl 7 days ago.


Historically, I’ve struggled to find a concise, simple way to explain what it means to practice type-driven design. Too often, when someone asks me “How did you come up with this approach?” I find I can’t give them a satisfying answer. I know it didn’t ju...
programming  functional  parsing 
2 days ago by vojtabiberle
Hopefully, by this point, you are at least somewhat sold on the idea that parsing is preferable to validation, but you may have lingering doubts. Is validation really so bad if the type system is going to force you to do the necessary checks eventually anyway? Maybe the error reporting will be a little bit worse, but a bit of redundant checking can’t hurt, right?

Unfortunately, it isn’t so simple. Ad-hoc validation leads to a phenomenon that the language-theoretic security field calls shotgun parsing.
[…]
In other words, write functions on the data representation you wish you had, not the data representation you are given. The design process then becomes an exercise in bridging the gap, often by working from both ends until they meet somewhere in the middle.

This is really, really good advice, not at all limited to Haskell but applicable to even simple frontend and template loops.
nützlch  Inspiration  Daten  Debugging  Meinungen  Best-Practice  Haskell  Schnittstellen 
4 days ago by Stolzenhain
Limit data on the way in. That way you force the constrain up the chain.
programming  types 
4 days ago by raygrasso
Parse, don’t validate via Instapaper https://ift.tt/2p018KI
Instapaper 
4 days ago by davidpdrsn
Historically, I’ve struggled to find a concise, simple way to explain what it means to practice type-driven design. Too often, when someone asks me “How did you come up with this approach?” I find I can’t give them a satisfying answer. I know it didn’t ju...
IFTTT  Pocket  best  categorytheory  functional  hacker  haskell  parsing  programming  types 
5 days ago by xer0x
Historically, I’ve struggled to find a concise, simple way to explain what it means to practice type-driven design. Too often, when someone asks me “How did you come up with this approach?” I find I can’t give them a satisfying answer. Parse, don’t validate
Archive  best  stories  hacker  news 
5 days ago by Agiza
Parse, Don’t Validate
from twitter_favs
6 days ago by demon386
> but `parseNonEmpty` gives the caller access to the information it learned, while `validateNonEmpty` just throws it away.

> Consider: what is a parser? Really, a parser is just a function that consumes less-structured input and produces more-structured output.
alexis-king  haskell  type-systems 
6 days ago by jasdev
Historically, I’ve struggled to find a concise, simple way to explain what it means to practice type-driven design. Too often, when someone asks me “How did you come up with this approach?” I find I can’t give them a satisfying answer. I know it didn’t ju...
6 days ago by kc5tja
Historically, I’ve struggled to find a concise, simple way to explain what it means to practice type-driven design. Too often, when someone asks me “How did you come up with this approach?” I find I can’t give them a satisfying answer. via Pocket
IFTTT  Pocket 
6 days ago by domingogallardo
Instead of writing predicate functions that validate a value, parse the value into a concrete datatype that reflects the properties it needs to have, e.g., a NonEmpty list type.
functional  Programming  types  haskell 
6 days ago by tncowart
In other words, write functions on the data representation you wish you had, not the data representation you are given. The design process then becomes an exercise in bridging the gap, often by working from both ends until they meet somewhere in the middle. Don’t be afraid to iteratively adjust parts of the design as you go, since you may learn something new during the refactoring process!
computers  programming  haskell  types  softwarearchitecture 
6 days ago by pozorvlak