Allow specify numbers with suffixes

kdex kdex at kdex.de
Thu Nov 23 13:22:33 UTC 2017


Please see [1].

[1] https://github.com/littledan/proposal-extensible-numeric-literals

On Thursday, November 23, 2017 2:16:44 PM CET Andrey Muzalevsky wrote:
> Idea is simple, also is simple to implement and do not conflicting with
> existing standard
> 
> Readability of javascript can be improved in certain cases like:
> 
>    - populationSize = 100000000
>    - maxMessageSize = 4194304
>    - setTimeout(foo, 30000)
>    - if(timeElapsed > 100) {...}
> 
> This can be changed to following:
> 
>    - populationSize = 100M
>    - maxMessageSize = 4MB
>    - setTimeout(foo, 30s)
>    - if(timeElapsed > 0.1s) {...}
> 
> Also it will be great to support floating number, most convinient way to do
> this is tract suffix just like a multipler, so
> 
> 1.5MB == 1.5 * 1MB
> 
> Supported suffixes, as I see them:
> 
>    - Metric prefixes group
>       - follow SI Prefixes
>       <http://www.npl.co.uk/reference/measurement-units/si-prefixes/>
>       scheme, to decrease entrance level
>       - allowing to use short and full form
>       - it is case sensetive (bad, but everyone knows it)
>       - not sure about μ, it either:
>       - (my preference) supported as UTF-8 sumbol, always can be replaced
>          with 'full' form when needed(is it recommended to use?)
>          - has a replace symbol which can be easily typed
>          - allowed only in full form
>       - samples:
>          - 4M == 4mega == 4 000 000
>          - 5n == 5nano == 0.000 000 005
>          - 1micro == 0.000 001
>       - Bytes prefixes group
>       - Metric prefixes turned into bytes prefixes by adding either 'B' to
>       short form, or 'byte[s]' to full form
>       - Byte suffix is written in upper-case 'B', e.g. 'kB', 'MB', 'GB'
>          - This is done to remove inconsistency with widely used
>          bit/byte differentiation, e.g. `kb` and `KB` usually mean
> different things
>       - Samples:
>          - 1kB = 1kilobyte = 1024
>          - 1MB = 1megabyte = 1024*1024
>       - Time group, counted in milliseconds
>    - s, sec = 1000
>       - min = 60 * 1000
>       - h, hr = 60 * 60 * 1000
>       - d, day[s] = 24 * 60 * 60 * 1000
>       - w, week[s] = 7 * 24 * 60 * 60 * 1000
>    - Also it will be good to allow compound number definitions, samples
>    - 1h 30min = 1h + 30min
>       - 1mB 200kB = 1mB + 200kB
> 
> 
> What do you think?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20171123/8d2bb43e/attachment-0001.sig>


More information about the es-discuss mailing list