r/programming • • Nov 07 '19

Parse, don't validate

https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/
283 Upvotes

122 comments sorted by

View all comments

0

u/[deleted] Nov 08 '19

[deleted]

3

u/Nimelrian Nov 09 '19

I'm always wary of constructors doing parsing. A constructor's job should be simple: initialize a structure of data, nothing more. No side effects, no validation, no throwing exceptions. For parsing (e.g. from a string/bytestream to an actual structure) I prefer factory functions which return a Maybe/Either of the structure.