proposal: encoding/json: fluent interface for SetIndent/SetEscapeHTML #33051
Labels
Milestone
Comments
Changing the method signature at this point would break the Go 1 compatibility guarantee (https://golang.org/doc/go1compat). As a pure style point, Go code tends to use fluent interfaces less than in some other languages, in part because fluent interfaces don't work in Go for functions/methods that need to return errors. |
OK, I am curious why this would break compatiblity? If a function returns 1 variable, you now return 2, or none, that's a break of compatibility, but if the function originally returns nothing, now you return one (or any more) that will not affect any existing code? |
This currently valid Go program would stop compiling. package p
import "encoding/json"
var F func(*json.Encoder, string, string) = (*json.Encoder).SetIndent |
This breaks compatibility, and it's not worth adding a second API. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
In the stdlib, it's defined as:
I suggest to make it fluent by:
So that it is more convenient to do this:
The text was updated successfully, but these errors were encountered: