2 ms·
It would break reflection surely? It's nice to have as a configuration / flag though as many project will be able to require it.
by radicalbyte 3y ago
It would break reflection surely? It's nice to have as a configuration / flag though as many project will be able to require it.
- erik_seaberg 3y agoLast I looked, reflection was missing a lot of things like looking up a function by name.
- zimpenfish 3y ago`MethodByName`[0] allows you to find a method on a struct but I'm assuming you must mean a generic package-level function rather than a method? [0] https://pkg.go.dev/reflect#Value.MethodByName https://pkg.go.dev/reflect#Value.MethodByName
- erik_seaberg 3y agoYeah, you can look up a method but only if you already have the receiver’s type (which you also can’t look up by name, or by listing a package).
- zimpenfish 3y agoYou don't need the receiver's type because you're calling `MethodByName` on a `reflect.Value` which you can construct from any receiver. https://go.dev/play/p/hg-ugl7i0ei https://go.dev/play/p/hg-ugl7i0ei demonstrates this, I think?
- enneff 3y agoGo’s reflect package is not “missing” that feature, it is intentionally omitted as it defeats static analysis. In all my years writing Go (14 now), including some tricky metaprogramming, I have never needed to look up a function by name.
- erik_seaberg 3y agoIt creates busywork and ongoing maintenance issues in writing an interpreter. E.g., https://pkg.go.dev/text/template https://pkg.go.dev/text/template requires every possible function to be manually registered, and that’s not a good use of time.