News for hackers. Stuff that matters.
Re:A New Go API for JSON by hnlmorg on Friday November 06, 2026 @04:00AM (#50389878)
> It's a function, not a method. So it can't be part of an interface.

The mashaller here is a function, yes. But having a consistent signature means you can interchange those marshallers. It’s a trick I use heavily in murex to enable typed pipelines.

And I do this via a pipe interface. So it’s not uncommon to reuse function signatures for interface types (fewer runtime abstractions) while retaining some level of dynamism.

> Say you are marshaling a struct that contains a struct from a third party library, and it works fine. Then you update to a new version of that library, and that added a new field for a type that doesn't work, say a map[A]string where A is a struct.

The first mistake there is to blindly forward an API struct that you don’t control and depend on that for business logic.

Which comes back to my point about if you want type safety then you’d create a struct.

I do take your point that the compiler in smarter languages would catch this. But you’d equally be told not to do this sort of thing on those languages too.

There are no comments on this comment yet.