-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fmt: consider altering %#v behaviour to include type information for simple types #6565
Labels
Comments
%#v means "a Go-syntax representation of the value" [0]. But Go-syntax representation of int(1) is '1', not 'int(1)'. Even though the later is valid, the former is the default/standard in idiomatic Go source code. #WorkingAsIntended or at least #Unfortunate PS: Yes, it would broke some of my own _test files. [0]: http://golang.org/pkg/fmt/ |
Labels changed: added priority-later, removed priority-triage. Owner changed to @robpike. Status changed to Thinking. |
Re:#1 That's why I picked float64 as the example type. A float64 does not print "1." with %#v, which would be the idiomatic way of assigning 1 to a float64. The rest? What about this, http://play.golang.org/p/vkOtAbL7s0. That's a lot of missing type information that would be required for Go syntax representation of the relevant values 1. It may not be fixable now, but it is at the very least unfortunate. |
@3 Go-syntax != {valid,complete}, compiler grade Go source code. {float64(1.0),int8(1)) printed as '1' is a correct behavior - 1.0 is exactly same as 1 in IEEE representation and int8(1) is exactly the same value etc. If one need more {debug,test} info, "%T(%#v)" is usable today (and is one of the sources of backward incompatibility introduced by the proposal). |
> Go-syntax != {valid,complete}, compiler grade Go source code. No, this is absolutely true, but Go syntax as a fmt option aids by giving type information in all other cases. You could have a Go syntax formatting that gave unnamed definitions of all composite type - but we don't have that. > {float64(1.0),int8(1)) printed as '1' is a correct behavior - 1.0 is exactly same as 1 in IEEE representation and int8(1) is exactly the same value etc. I don't believe you can make a claim for correctness or otherwise here; it comes down to a design decision. 1.0 make well be exactly the same value as 1, but 1. or float64(1) give this type information, but this doubles up that information in cases where the type is not a simple type, e.g. http://play.golang.org/p/oeFhSO8_b7 So now we have an approach that is not truly general (an break in symmetry is often - maybe in this case - an indication of a design mis-step and something that is often raised when people discuss Go design principles). > If one need more {debug,test} info, "%T(%#v)" is usable today (and is one of the sources of backward incompatibility introduced by the proposal). The first part is addressed above, but I don't understand how this particular thing is any more of a backward incompatibility that any other use of %#v where people are comparing against expected values. Note that I did raise the compatibility issue in the initial ticket. I see this as a Go2-if-ever issue. What initially spurred this was that if you have a type F float64, %#v does not format that differently to float64, yet there was some intention in the definition of F, so why not reflect that. |
It's been pointed out to me that if the argument that changing %#v behaviour is taken to its logical extension, changing (in any way) the fields of a struct that does not implement fmt.{Stringer,Formetter} would be breaking the compatibility promise since the output with %#v (and many other verbs for that matter) would be changed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: