Live data from Hacker News

Stop writing CLI validation. Parse it right the first time

hackers.pub

1–10 of 169 posts

Re: Stop writing CLI validation. Parse it right the first time

#2
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!

Re: Stop writing CLI validation. Parse it right the first time

#3
I, for one, do think the world needs more CLI argument parsers :)

This project looks neat, I've never thought to use parser combinators for something other than left-to-right string/token stream parsing.

And I like how it uses Typescript's metaprogramming to generate types from the parser code. I think that would be much harder (or impossible) in other languages, making the idiomatic design of a similar similar library very different.

Re: Stop writing CLI validation. Parse it right the first time

#8

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!

Last week my primary task was writing a github action that needed to log in to Heroku and push the current code on main and development branches to the production and staging environments respectively. The week before that, I wrote some code to make sure the type the object was included in the filters passed to an API call.

Don't get me wrong, I actually love writing parsers. It's just not required all that often in my day-to-day work. 99% of the time when I need to write a parser myself it's for and Advent of Code problem, usually I just import whatever JSON or YAML parser is provided for the platform and go from there.

Re: Stop writing CLI validation. Parse it right the first time

#9
> Think about it. When you get JSON from an API, you don't just parse it as any and then write a bunch of if-statements. You use something like Zod to parse it directly into the shape you want. Invalid data? The parser rejects it. Done.

Isn’t writing code and using zod the same thing? The difference being who wrote the code.

Of course, you hope zod is robust, tested, supported, extensible, and has docs so you can understand how to express your domain in terms it can help you with. And you hope you don’t have to spend too much time migrating as zod’s api changes.

Re: Stop writing CLI validation. Parse it right the first time

#10
post #8

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!

Last week my primary task was writing a github action that needed to log in to Heroku and push the current code on main and development branches to the production and staging environments respectively. The week before that, I wrote some code to make sure the type the object was included in the filters passed to an API call. Don't get me wrong, I actually love writing parsers. It's just not required all that often in…

Do you not write validation? Or handle user input? Or handle server responses? Surely there’s some data processing somewhere.
Post reply on HN