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
Change strconv.FormatInt to be a generic that accepts any integer type.
Deprecate strconv.FormatUint and suggest to use strconv.FormatInt instead.
Motivation
During a review of a medium-sized codebase I have noticed that there are two causes of typecasts to the arguments of strconv.Format[U]Int: casting integers to a wider type, and casting non-integers (floats, types based on integers). These two cases are hard to distinguish and as a result of the review we had to add a comment to every typecast.
First type of casts (wider-type casts) ought not exist, they are an artifact of Format[U]Int been created before generics. This proposal gets rid of the useless typecasts of first type, leaving only second, meaningful, typecasts in place.
As far as I can tell this proposal does not break backward compatibility, as it makes FormatInt accept strictly more types than before.
The text was updated successfully, but these errors were encountered:
This kind of change is not backward compatible, unfortunately. Code today can write var f = strconv.FormatInt, which would become illegal if FormatInt were given type parameters. See #48287.
Description
strconv.FormatInt
to be a generic that accepts any integer type.strconv.FormatUint
and suggest to usestrconv.FormatInt
instead.Motivation
During a review of a medium-sized codebase I have noticed that there are two causes of typecasts to the arguments of
strconv.Format[U]Int
: casting integers to a wider type, and casting non-integers (floats, types based on integers). These two cases are hard to distinguish and as a result of the review we had to add a comment to every typecast.First type of casts (wider-type casts) ought not exist, they are an artifact of
Format[U]Int
been created before generics. This proposal gets rid of the useless typecasts of first type, leaving only second, meaningful, typecasts in place.As far as I can tell this proposal does not break backward compatibility, as it makes
FormatInt
accept strictly more types than before.The text was updated successfully, but these errors were encountered: