spec: abandon remaining ambiguity in definition of integer and floating point types #51186
Labels
Documentation
Issues describing a change to documentation.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
@griesemer
EDIT: Significantly improved the description of the issue.
Introduction
In issue #49804 I pointed out the the terms integer type, floating-point type and complex type were not defined, but used in several places in the language specification in order to define other terms. The missing definition lead to ambiguity, most notably about which types are permissible for array or slice indices. For example the go compiler did accept indexing by
uint32
while the officially recommended debugger dlv did not recognize indexing by uint32 when using the commandprint
.In discussion of issue #49804 the necessity to define the terms was acknowledged as a known problem. The draft of the specification for go version 1.18 now introduces these terms explicitly. Accordingly, issue #49804 was closed. However, exactly the same ambiguity that existed before is now encapsulated in the new and explicit definition of the terms integer type, floating-point type and complex type as of the draft of go version 1.18.
This issue differs from issue #49804 in so far as in this issue I provide a specific proposal on how the ambiguity can be resolved properly.
Short and informal description of the problem and the proposed changes
A short explanation of the problem
In the current version the terms integer type, floating-point type and complex type are introduced in the section about numeric types with the sentence:
Then in the same section, the predeclared architecture-independent and architecture-dependent numeric types are introduced. The problem is that it is nowhere explicitly stated which of these are of integer-type, of floating-point type or of complex type.
Even novice programmers might intuitively assume that for example
complex64
is not of integer type, anduint32
not of floating-point type. But less experienced programmers, or programmers for whom writing safe code is of concern might reasonably assume, that for example indexing by any non-int
type is a feature of the compiler and not of the language itself.Actually, it is not even clearly stated that these classes do do not overlap, i.e. it is not clear that a type of integer type cannot simultaneously be of floating-point type.
A short explanation of the proposed changes
I propose to rewrite the section about numeric types. Instead of introducing the predeclared numeric types all together I propose to introduce the predeclared integer, floating-point and complex types individually.
Explicit wording of the current and proposed version
Current version of the section about numeric types
I propose to change the current version of the section about numeric types, which is:
The version of the section about numeric types including the changes that I propose
I propose to change that section to include the following instead:
Discussion
This proposal resolves the ambiguity in such a way, that the definition of the individual numeric types is as broad as possible. I guess, this is in accordance with the intention of the current wording.
With this proposal any ambiguity about what integer, floating-point, or complex types are is resolved in a disputable, but hopefully sensible manner. As a notable example, from this adjusted definition it is now clear, whether in the language
specification indexing by integer types includes includes indexing by
int32
, too, or unsigned integer types, in contrast to the previous version, where this was not clear from the language specification itself.Since the previous definition was ambiguous, it is disputable, whether the adaption of this proposal does any breaking changes. Since effectively some behavior of the go compiler (for example with regard to indexing) could be argued to be a feature of the compiler and not the language itself.
I suspect the current compiler as well as other tools already are conformal to the proposed change to the language specification. However, I did not test this thoroughly. The expected cost of this proposal is to review, whether
current tools indeed accept the numeric types as defined above (and reject others) whenever this is enforced by the language specification. I suspect the cost of adapting this proposal to be low.
This proposal would make Go easier to learn. Moreover, less experienced programmers would benefit most from this proposal, as more experienced programmers are more likely to intuitively assume the interpretation of the language specification, which is now made explicit with this proposal, and most likely already fully implemented by the go tool chain.
The text was updated successfully, but these errors were encountered: