← Back to context

Comment by hnlmorg

23 days ago

I wouldn’t class unmarshallable data as a compile time error.

Plus the point of the marshal interface is that it’s reusable.

It could be if go had a more powerful type system.

  • This isn’t a type system problem. It’s a data origin problem. Ie it could be any random JSON blob a user entered. The compiler doesn’t know this ahead of time.

    If you wanted type safety with JSON in Go then don’t use the marshal interface. Period.

    • For unmarshalling, but the original complaint was about marshalling. And for that the type system could help if the marshal API only allowed you to marshal objects of types that supported marshalling.

      And even for unmarshalling you could get a compile time error if you try to unmarshall to a type that doesn't support it.

      15 replies →