Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
fmt: Printf `%d` printing functions as integers confuses newbies #12295
From IRC: http://play.golang.org/p/AnMCdU2VM1
w := bufio.NewWriter(os.Stdout) fmt.Printf("Available: %d \n", w.Available)
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
"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.