News for hackers. Stuff that matters.
Re:argp: GNU-style command line argument parser for Go by cedws on Monday March 24, 2025 @12:35AM (#43457806)
Struct tags = reflection, and reflection is nasty. They also aren't validated at compile time. Liberal use like this should be avoided.
Re:argp: GNU-style command line argument parser for Go by quacker on Monday March 24, 2025 @02:39AM (#43458213)
In what way is reflection nasty?

What compile-time validation do I actually lose by using struct tags for CLI arg parsing?

Re:argp: GNU-style command line argument parser for Go by cedws on Monday March 24, 2025 @07:24AM (#43459666)
Reflection is slow and bug prone. Struct tags are widely considered in the Go community to be a nasty hack yet a necessary evil. They should be used at little as possible because if you mess them up you don't get a compile error, you get a runtime error.
Re:argp: GNU-style command line argument parser for Go by 9rx on Monday March 24, 2025 @12:05PM (#43462592)
> Reflection is slow

Beware of microbenchmarks, but in my tests the above package only added around 0.001 ms over the standard library flag package. Even if real world usage increases that by several orders of magnitude, it isn't going to matter. No human will ever notice.

Re:argp: GNU-style command line argument parser for Go by CamouflagedKiwi on Monday March 24, 2025 @05:46AM (#43459015)
Do you also avoid using packages like encoding/js, which make equally liberal use of struct tags and reflection?
Re:argp: GNU-style command line argument parser for Go by cedws on Monday March 24, 2025 @07:23AM (#43459657)
encoding/json does not make liberal use of struct tags, it uses only one. It's also battle tested and lives in the standard library. I don't have faith in many other projects to get bug-prone reflection code right.
Re:argp: GNU-style command line argument parser for Go by CamouflagedKiwi on Wednesday March 26, 2025 @09:21AM (#43482000)
It does have a microformat within that single tag though ("x,omitempty" etc) so there is a bit more complexity than 'just one tag' indicates.

Anyway, I think you're overstating how hard reflection-based code is. Yes, it is tricky and should mostly be avoided, but it's not beyond the scope of human intellect to understand (especially Go's which is pretty sensible).