4 ms·
I think it's nice that you can basically document the expected response, in the form of creating a type with a struct. In pseudo-code-ish: type FacebookUs
by FuzzyDunlop 14y ago
I think it's nice that you can basically document the expected response, in the form of creating a type with a struct.
In pseudo-code-ish:
type FacebookUser struct {
ProfileID int
Name string
....
}
json.Unmarshal(response, FacebookUser)
Compare it to the implementations that just give you a hash:
json_decode($response);
json.parse response
Yeah, you can document it with comments, or visit the API documentation, but you can fix the code and let your comments go stale. You fix both your documentation and your implementation in one go in the first example.
It's certainly why I find it more appealing, anyway. Makes me feel more secure in my code.