News for hackers. Stuff that matters.
Re:Green vs. Brown Programming Languages by majewsky on Sunday April 25, 2021 @01:32PM (#26934591)
> JSON parsing, config file handling

I assume you're not referring to things like json.Marshal(), where the function argument is legitimately of type interface{} since it really accepts any value.

Hence I'm going to assume that you're referring to situations where a value can have one of multiple types (e.g. a float value that sometimes gets provided as a string). It's true that people sometimes unmarshal into interface{} and then type-assert in those scenarios, but that use of interface{} is a code smell that should be flagged in review. The proper way is to unmarshal into a custom type with a json.Unmarshaler implementation that accepts all possible input formats (and vice versa for json.Marshaler if encoding is required). This is a real-world example from one of my codebases: https://github.com/sapcc/limes/blob/d833228e976ac1ddc4b95779...

Re:Green vs. Brown Programming Languages by gher-shyu3i on Wednesday April 28, 2021 @10:11AM (#26969563)
Algebraic types would solve the issue in the example you're giving. However, those don't exist in golang either.