-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
x/tools/go/analysis/passes/printf: simplify fmt.Sprintf("%s", x) -> x.String() et al #73027
Comments
It's true that in many cases these expressions could be simplified, but the benefits seem fairly marginal. Let's take them in turn:
I wonder how common cases 5 and 2 are. I suspect rare, compared to uses of %s within a larger format string. |
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
Could 1
I found a few dozen packages matching There are also many hundreds of calls like
|
Yes, if you know the type the transformation is sound.
I'm not worried about that.
Both of those are redundant with Print, but they're really not mistakes--perhaps the author is following a local style rule of "prefer Printf over Print{,ln}"--so they're out of scope for vet's printf checker. Ditto your other examples. |
That's a good call, something I hadn't considered. There is enough room for doubt in each of these cases that we should probably leave these calls alone. |
There are surprisingly many calls like
As I write this, I feel that somewhere in the history of Go this surely has come up before, but I couldn't find anything in the issue tracker or with some quick code searches.
In Google there seem to be thousands of calls like these. A rewrite would make the code more readable and more performant, so why not nudge users in this direction?
The text was updated successfully, but these errors were encountered: