You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
which leads to additional iterations and manual comments on pull requests. I was asked if this can be checked with a linter instead (google/syzkaller#678 (comment)).
Using %v unless something special is needed feels more idiomatic and looks better to me because:
no need to remember types of all fields
more robust on var type changes
also prints arrays and structs
But now I can't actually find any documentation anywhere that %v is indeed more idiomatic and the recommended way. So is it really the recommended way? Are there any advantages in using %d/f/s in common case? Does it make sense to make lint to warn when %v would give the same format?
Personally I've always preferred using exact verbs. Vet complains when the types of arguments don't match the verbs, which acts as a kind of soft static checking of Printf calls. For example, it can protect against incorrect order of arguments.
I too prefer exact verbs sometimes, in particular when I know I want that type of data to be printed. For example, if a tool is supposed to print a number, I don't want it to happily print a string or a slice if I somehow mess up the code.
Context:
People with C/C++ background tend to do unnecessary detailed verbs in format strings, i.e.:
instead of:
which leads to additional iterations and manual comments on pull requests. I was asked if this can be checked with a linter instead (google/syzkaller#678 (comment)).
Using %v unless something special is needed feels more idiomatic and looks better to me because:
But now I can't actually find any documentation anywhere that %v is indeed more idiomatic and the recommended way. So is it really the recommended way? Are there any advantages in using %d/f/s in common case? Does it make sense to make lint to warn when %v would give the same format?
@dominikh
The text was updated successfully, but these errors were encountered: