Looking on parsing numbers in lex.cpp, I have few notes:
Octal numbers are relic of the ancient past. I think it was a PDP computer which used them regularly last time.
Walter Bright, author of the D language recently talked, how having them in his language was mistake (here at 12:14 https://youtu.be/p22MM1wc7xQ?t=734 ). D allows leading zeros, making things more bug prone.
It would improve readability, if it was possible to insert a visual separator between the numerals, e.g. underscore _:
132_780, 0xFF60_88A1_73E9_6620, 0b0110_1110
The separator could be single quote ', as they do it in India; or minus -, if math operators require space before and after. (This would also allow to use - in names, making them more readable.)
Binary and hex numbers should always have size 1, 2, 4, or 8 bytes (filled with leading zeros, if needed). People are not used to read/write them, it is much easier to make a mistake here. Possible separator inside these numbers should preferably be also on these boundaries. If binary/hex is assigned to a known sized integer, the whole sized number should be written.
A bug. This code accepts integer value out of its range (has to be negative, overflow of positives is checked):
void main() {
int8 a = -0xFFFF;
println(a);
}
Scientific float notation could be supported.
Hex notation for floats could be supported, to make precise values and NaNs.
In lex.ccp, function Lexer::readNumber(), I was surprised to see the name end to be used as both a local identifier and as a label. It is a bit confusing to see such a (valid by standard) trick.
Looking on parsing numbers in
lex.cpp
, I have few notes:Octal numbers are relic of the ancient past. I think it was a PDP computer which used them regularly last time.
Walter Bright, author of the D language recently talked, how having them in his language was mistake (here at 12:14 https://youtu.be/p22MM1wc7xQ?t=734 ). D allows leading zeros, making things more bug prone.
It would improve readability, if it was possible to insert a visual separator between the numerals, e.g. underscore
_
:132_780, 0xFF60_88A1_73E9_6620, 0b0110_1110
The separator could be single quote
'
, as they do it in India; or minus-
, if math operators require space before and after. (This would also allow to use-
in names, making them more readable.)Binary and hex numbers should always have size 1, 2, 4, or 8 bytes (filled with leading zeros, if needed). People are not used to read/write them, it is much easier to make a mistake here. Possible separator inside these numbers should preferably be also on these boundaries. If binary/hex is assigned to a known sized integer, the whole sized number should be written.
A bug. This code accepts integer value out of its range (has to be negative, overflow of positives is checked):
Scientific float notation could be supported.
Hex notation for floats could be supported, to make precise values and NaNs.
In
lex.ccp
, functionLexer::readNumber()
, I was surprised to see the nameend
to be used as both a local identifier and as a label. It is a bit confusing to see such a (valid by standard) trick.