I've noticed that many programmers believe that parsing is some niche thing that the average programmer likely won't need to contend with, and that it's only applicable in a few specific low-level cases, in which you'll need to reach for a parser combinator library, etc . But this is wrong. Programmers should be writing parsers all the time!
Stop writing CLI validation. Parse it right the first time
11–20 of 169 posts
Re: Stop writing CLI validation. Parse it right the first time
#12Isn’t this like argparse from Python for typescript?
Re: Stop writing CLI validation. Parse it right the first time
#13I was recently thinking about type safety and validation strategies are particularly thorny in languages where the typings are just annotations. E.g. the Typescript/Zod or Python/Pydantic universes. Especially in IO cases where the data doesn't originate in the same type system.
In a language like Go (just an example, not endorsing) if you parse something into say a struct you know worst case you're getting that struct with all the fields set to zero, and you just have to handle the zero values. In typescript-likes you can get a totally different structure and run into all sorts of errors.
All that is to say, the runtime validation is always somewhere (perhaps in the library, as they often are?), and the feature here isn't no runtime validation but typed cli arguments. Which is cool and great.
Re: Stop writing CLI validation. Parse it right the first time
#14Stopped reading after realising this is written by ChatGPT
What makes you think that and not that it's just an average auto-translate job from the author's native language (Korean)?
Re: Stop writing CLI validation. Parse it right the first time
#15I've noticed that many programmers believe that parsing is some niche thing that the average programmer likely won't need to contend with, and that it's only applicable in a few specific low-level cases, in which you'll need to reach for a parser combinator library, etc . But this is wrong. Programmers should be writing parsers all the time!
Re: Stop writing CLI validation. Parse it right the first time
#16https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va... (2019, using Haskell)
https://www.lelanthran.com/chap13/content.html (April 2025, using C)
Re: Stop writing CLI validation. Parse it right the first time
#17I've noticed that many programmers believe that parsing is some niche thing that the average programmer likely won't need to contend with, and that it's only applicable in a few specific low-level cases, in which you'll need to reach for a parser combinator library, etc . But this is wrong. Programmers should be writing parsers all the time!
Sometimes it's going down to machine code, or rolling your own hash table, or writing your own recursive-descent parser from first principles. But most of the time you don't have to reach that low, and things like parsing are but a minor detail in the grand scheme. The engineer should not spend time on building them, but should be able to competently choose a ready-made part.
I mean, creating your own bolts and nuts may be fun, but mot of the time, if you want to build something, you just pick a few from an appropriate box, and this is exactly right.
Re: Stop writing CLI validation. Parse it right the first time
#18Re: Stop writing CLI validation. Parse it right the first time
#19> Try to access it and TypeScript yells at you. No runtime validation needed. I was recently thinking about type safety and validation strategies are particularly thorny in languages where the typings are just annotations. E.g. the Typescript/Zod or Python/Pydantic universes. Especially in IO cases where the data doesn't originate in the same type system. In a language like Go (just an example, not endorsing) if you…
In the field I work, zero values are valid and doing it in Go would be a nightmare
Re: Stop writing CLI validation. Parse it right the first time
#20This is a recurring idea: "Parse, don't validate". Previously: https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va... (2019, using Haskell) https://www.lelanthran.com/chap13/content.html (April 2025, using C)