Skip to content
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

Number literal syntax - allow underscores or other way to make number more readable #26845

Closed
rakudrama opened this issue Jul 8, 2016 · 6 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug

Comments

@rakudrama
Copy link
Member

This is likely a 2.x feature.

I would like to be able to use underscores inside number literals to break up long runs of digits.
For example 1000000000 is harder to understand than 1_000_000_000.

Today I saw x & 0x3FFFFFF with a comment saying the result fits in 30 bits.
If you count the Fs, you will see there is an error, but the error has gone unnoticed for several years.
If underscores were permitted, the following difference might be more apparent to the developer or reviewer:

x & 0x_3FF_FFFF     vs     x & 0x_3FFF_FFFF

I would want the exact placement of underscores not be prescribed, the same literal might warrant different structure depending on context. In some byte-oriented code 0x3F_FF_FF_FF might make more sense.

This feature would also make binary literals (0b_1111_1111 = 255) more useful.

@rakudrama rakudrama added the area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). label Jul 8, 2016
@zoechi
Copy link
Contributor

zoechi commented Jul 9, 2016

See also #2995

@lrhn lrhn added the type-enhancement A request for a change that isn't a bug label Jul 9, 2016
@lrhn
Copy link
Member

lrhn commented Jul 9, 2016

That feature is on my (rather long) list of conveniences I'd like too.

My design would only allow underscores between digits, so 0x3FFF_FFFF, not 0x_3FFF_FFFF, but apart from that I agree.

@floitschG floitschG mentioned this issue Feb 14, 2017
16 tasks
@rakudrama
Copy link
Member Author

I found another example of the initial problem of a wrong literal: fc67a19

@lrhn
Copy link
Member

lrhn commented May 16, 2019

I reasonably often see code like 100 * 1000 * 1000 to dodge the issue. That could just have been 100_000_000.

@srawlins
Copy link
Member

I think we can close this in favor of dart-lang/language#2 in the new language repo; 20 upvotes today.

@lrhn
Copy link
Member

lrhn commented Oct 22, 2019

Now that you have linked the two, I agree :)

@lrhn lrhn closed this as completed Oct 22, 2019
@lrhn lrhn added the closed-duplicate Closed in favor of an existing report label Oct 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants