News for hackers. Stuff that matters.
Re:OAuth 3 by speedgoose on Thursday October 22, 2020 @11:30AM (#24859070)
In my humble opinion, Golang is pretty verbose in a bad way when it comes to JSON. Rust and the crate serde_json are also strongly typed and it's a lot better.
Re:OAuth 3 by curryst on Thursday October 22, 2020 @01:38PM (#24860722)
Yeah, having done this, it's extremely verbose if you have all your error handling in there due to the verbosity of dealing with JSON and explicit return values instead of exceptions. By far my greatest annoyance is that []interface{} cannot be directly cast to []concreteType. Having to make a sized slice and type assert each value is annoying. Require validation of the values for even more "if err != nil" fun.

Many Go advocates seem to consider the verbosity a feature, because it's explicit and forbids any clever-but-confusing tricks.

Re:OAuth 3 by q3k on Thursday October 22, 2020 @11:40AM (#24859196)
How would you express deserializing these 'polymorphic JSON' objects using serde/Rust?
Re:OAuth 3 by speedgoose on Thursday October 22, 2020 @11:44AM (#24859255)
Using a rust enum I guess.
Re:OAuth 3 by q3k on Thursday October 22, 2020 @11:54AM (#24859359)
You're right, this does seem to work [1]. I wasn't aware that serde would attempt to deserialize multiple enum variants until something matches.

[1] - https://serde.rs/enum-representations.html#untagged

Re:OAuth 3 by masklinn on Thursday October 22, 2020 @12:05PM (#24859509)
Yeah that's a rather common scheme out there so Serde does provide built-in support for this deserialisation. Probably better for deserialisation performances to use properly tagged enums, but if you don't have a choice Serde's got your back.