protected def getNumber(): Unit = { // consume digits of a radix | |
def consumeDigits(radix: Int): Unit = { var lastIsUnderscore = false; | |
while (digit2int(ch, radix) >= 0 || ch == '_') { if(ch != '_') { | |
putChar(ch) lastIsUnderscore = false; } else { lastIsUnderscore = true; } | |
nextChar() | |
} if(lastIsUnderscore) { //TODO: howdo I throw an error if the last char in the number sequence is an _? } } | |
--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-debate...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The presentation of numeric literals seems, to me, as an IDE concern--not a language concern.
--
Cheers,
√
Hi Dennis,
Different languages have different thousands separators, typically ‘.’, ‘,’ or ‘ ‘ (dot, comma and space, and different unicode spaces at that).
If Scala adopts just one of these, it could be unnecessarily inconvenient or confusing for speakers of other languages. But most likely no-one uses underscores and they won’t confuse people.
BTW, in your example, presumably you meant 1,000,000.345. I don’t think we should change the decimal separator to a comma :-)
I think the underscores look ugly in that context, but there's no requirement to use them, so it needn't affect most people. I'd quite like the 1000s grouping to be enforced by the compiler, though, so that `10_00.00` would not be legal.
As an argument against enforces thousands groupings, think of the case where you have an Int/long representing cents, then you may want something like,
val amount = 29_995_00
Anoher useful thing would be grouping bytes or shorts in hex format.
What's different in terms of floating point numbers?
I'm opposed to this.
I don't think doing it "because java did" is convincing: many other similar java syntaxes around literals were added and then had to be excused (octal literals, trailing . floats, ...) and others hang around and still cause grief (Unicode escapes...). Also, Scala.js is not a thing, and Scala is definitely bigger than "a better java" by this point.
Also, the alternatives have not been properly covered. The alternatives now are:
123 * 1000 * 1000 for round numbers
n"123,456,789" for non-round-numbers
Which look perfectly fine for me. It is 3 extra chars in the latter case, which hurts, but I'd like to see a piece of code with sufficient density of long numbers that the three extra chars is problematic. The comparisons so far have been against very-non-optimal use of what already exists so of course it looks better.
Lastly, we've all talked about making the language smaller, and thus definitely makes it bigger. By a small amount, but all the small amounts add up!
That's all I have to say
What's different in terms of floating point numbers?