TriggerReactor

TriggerReactor

24.6k Downloads

Proposals: Numeric Separators

Sayakie opened this issue ยท 2 comments

commented

This feature enables developers to make their numeric literals more readable by creating a visual separation between groups of digits. Large numeric literals are difficult for the human eye to parse quickly, especially when there are long digit repetitions. This impairs both the ability to get the correct value / order of magnitude.

1000000000    // Is this a billion? a hundred millions? Ten millions?
20230711.1349 // What scale is this? what power of 10?

Using underscores (_, U+005F) as separators helps improve readability for numeric literals, both integers and floating-point (in TriggerReactor, it's all doubles anyway):

1_000_000_000    // Ah, so a billion
20_230_711.1349  // And this is hundreds of millions

Also, this works on the fractional parts, too:

0.000_001 // 1 millionth

References

commented

Sounds like a good idea!

I think the challenge will be deciding where we are going to recognize it.

Should we put it as a part of lexical analysis?

Also, as an extension to this idea, we could add some indicator postfix for ambiguous numeric values, like float or long, which we possibly could explicitly define it by 'L' or 'f' postfix after the numeric values (ex. 1848583L or 84.2245f)

Just my ideas though

commented

One approach could be include it as part of the lexical analysis phase, where the code is broken down into tokens. This way, the separators can be recognized early on and treated as individual tokens.

Regarding the indicator postfix for ambiguous numeric values, such as float or long, adding postfixes like 'L' or 'f' after the numeric values can provide explicit clarity. This extension can help avoid confusion when working with different numeric types.

These are great ideas that can enhance the TriggerReactor language's syntax and improve the developer experience. So overall, our ideas have great potential to make the language even better ๐Ÿ‘๐Ÿป