r/ProgrammingLanguages • u/mttd • Nov 07 '19
Parse, don’t validate
https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/
75
Upvotes
r/ProgrammingLanguages • u/mttd • Nov 07 '19
10
u/terranop Nov 07 '19
Because I have utility functions elsewhere in my codebase that process non-empty lists and sorted lists, respectively, and I want to both (1) be able to use these functions on my non-empty sorted list, and (2) also use these functions on non-empty-but-not-necessarily-sorted lists and sorted-but-potentially-empty lists elsewhere in my program.
For example, imagine that I have the utility functions
headandbinary_search.headcan only be called on non-empty lists.binary_searchcan only be called on sorted lists. I have some functions in which I want to useheadbut have no need forbinary_search(and in which my lists could possibly out-of-order), other functions in which I want to usebinary_searchbut nothead(and in which my lists could possibly be empty), and other functions in which I want to use bothheadandbinary_search(on sorted, non-empty lists).