-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
pick names for fixed-size integer types #543
Comments
I prefer 2 and 3 over 1, because they don't require remembering a somewhat arbitrary name -> width mapping, don't give any option the name I prefer 3 over 2, simply because these types are common and a terse name seems helpful. I prefer 3b over 3A, because I don't think |
I'd defer A vs B to a more general decision. Presumably we'll want to name several other built-in types, as well as standard library components, and we'll probably want them to use the same capitalization convention. I mildly prefer 2 over 3 because the longer names stand out ever so much more and avoid confusion with variable names. (E.g. consider Even though I feel some nostalgia for 1, there's probably too much baggage attached to chars, strings and aliasing to make "char" a tolerable name for an integer type. But on that note, we should probably also discuss byte types and string code unit types at some point, which may feed back into this discussion. And what about an integer type for round-tripping with pointers, will that be an alias or also a distinct fundamental type? |
The current plan of record is that type names (like all other compile-time constants) should have camel-case names, and I don't think it would be a good idea to make an exception for something so fundamental as integer types, so I think we should choose (A) unless we want to reconsider that whole policy. I prefer 2 over 3, because I agree with @zygoloid that I prefer 2 over 1 for the reasons already cited by others. I think we might want to consider having a type (or alias?) named |
@geoffromer What would you do for unsigned values? |
I largely agree with @geoffromer's summary. For unsigned: However, I'll offer a potential rationale for We could say that
I think the biggest downside of this is we do have to decide "which types merit these aliases?" and stop adding them at some point. However, I think there are defensible heuristics here that we could pick and stick with it. Some candidates:
Maybe there are other heuristics, or tweaks to these heuristics... To be honest, I'd be happy with any of these. I'd even be happy with this being completely ad-hoc and simply reflecting what makes code more readable, including easing the reading by C/C++ programmers. I somewhat prefer having I prefer having these alias keywords purely based on the ergonomics. But I could live without them. |
Yeah, either of those seem fine, and Chandler's rationale for preferring the latter makes sense to me.
I don't have a good intuition for why these would be more ergonomic, other than the sheer reduction in keystrokes, which I think is offset (or more than offset) by the reduced readability that comes from abbreviation. The first two points here seem to assume the conclusion (that |
This came up in open discussion today, and I think everyone (including both me and @zygoloid among the leads) was surprisingly happy trying out the super simple rule of The biggest downside of that is likely We can also move toward a Provided we don't get any new information, or other serious concerns, this is maybe our decision for now? |
Does that include |
Not in this issue. We should get a separate question for that. |
In particular, I've heard that we don't want to consider |
Also checked with @KateGregory and we have consensus here so closing. |
Lex [iuf][1-9][0-9]* as a new kind of "sized type literal" token. When parsing that token, form a literal expression. Co-authored-by: Chandler Carruth <[email protected]>
Note this doesn't support other sizes or types, it just errors on them. Co-authored-by: Geoff Romer <[email protected]>
I would like to note a typo concern: If Glancing at Rust and Swift my impression is both provide only limited forms, not the arbitrary digit forms. Note this will also have curious implications for the prelude, to the extent that we'd discussed having |
Lex [iuf][1-9][0-9]* as a new kind of "sized type literal" token. When parsing that token, form a literal expression. Co-authored-by: Chandler Carruth <[email protected]>
Note this doesn't support other sizes or types, it just errors on them. Co-authored-by: Geoff Romer <[email protected]>
Filed #1998 to track turning this into a proposal. |
We should have names for integer types with fixed widths. For the moment I'm only considering signed, two's-complement integer types that are expected to match native machine register widths: at least 8, 16, 32, and 64 bit varieties should be supported. Some possible options:
char
is the 8-bit type,short
is the 16-bit type,int
is the 32-bit type,long
is the 64-bit type.int
with a length suffix:int8
,int16
,int32
,int64
. This somewhat mimics theintN_t
typedefs from C++.i
with a length suffix:i8
,i16
,i32
,i64
. This follows Rust (and LLVM).Orthogonally, but not independently: (A) capitalize the first letter, (b) do not capitalize the first letter.
The text was updated successfully, but these errors were encountered: