-
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: Printf %d
printing functions as integers confuses newbies
#12295
Comments
Is there a reasonable situation where someone might want to format a function pointer as a base-10 number? It would be a shame to deny that because of a rare misunderstanding. (Have you seen this come up more than once?) |
"Reasonable" is very subjective. Right now functions behave just like pointers, which includes I do not necessarily mean fmt behavior should change; I'm merely documenting the problems I see more than one person having. This misunderstanding may still be rare, but I've seen more than one person succumb to it; the part that especially tricks them is when they expected to see a number, and can't tell what they're seeing is a completely different kind of a number. Perhaps there is an alternate route, e.g. via |
Possibly worth catching in vet but I am unconvinced. There's little point in ever printing a function value; you can't even compare function values. But it's a pretty rare case and the "newbie" argument is never compelling. A better solution might just be to teach newbies to use %T when they are confused. Vet's job is not to catch every possible mistake. |
This just came up here: https://go-review.googlesource.com/#/c/14031/1/src/cmd/compile/internal/gc/fmt.go |
Yes. I think it's such an easy thing to add to vet's existing print checker that it should be done. |
CL https://golang.org/cl/14122 mentions this issue. |
From IRC: http://play.golang.org/p/AnMCdU2VM1
The fix is obvious to you and me, but the fact that a fix is needed is not obvious to an unsuspecting mind.
I wonder if that could be changed to require %p (and make %v show something that doesn't look as easily confused; ideally a string that identifies it as a function), similar to the
%!d(string=Hello, playground)
handling.The text was updated successfully, but these errors were encountered: