Welcome! Please see the About page for a little more info on how this works.

+13 votes
in Syntax and reader by
edited by

Just saw as part of Go 1.13 they added:

Digit separators: The digits of any number literal may now be separated (grouped) using underscores, such as in 1_000_000, 0b_1010_0110, or 3.1415_9265. An underscore may appear between any two digits or the literal prefix and the first digit.

And I thought that's a pretty neat feature. When writing big numbers, such as 92347683 it can be hard to read and parse mentally if this is million, billion, etc. Having a syntax for separation I think would be a nice addition to the reader. Doesn't have to be underscores, and might need some hammock time when considering all the valid Clojure number literal.

Thank You

1 Answer

0 votes
by

A case against this would be that it could affect search over code. Say you want to search for where in the code is the number 10000, you'd have to search for 10_100 as well, or maybe 100_00, etc.

Not sure this is a deal breaker, can't remember the last time I searched for a number in a code base, but still worth considering.

by
That's true of Java since Java 7 which added the underscore as separator, I believe:

https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html
by
A similar argument against this which was brought up for adding raw strings, is that this could also complicate tooling, maybe for little benefits. Anything that makes parsing harder and with more edge cases basically can impact tools.
by
> it could affect search over code.

Tell it to ::namespaced/keyword syntax and namespaced maps. It is true that it makes number literals less greppable, but clojure is already not greppable at all.
...