crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.33k stars 1.61k forks source link

`Number#humanize` and `Int#humanize_bytes` should separate number and unit by a space #14349

Open philipp-kempgen opened 6 months ago

philipp-kempgen commented 6 months ago

Discussion

Number#humanize and Int#humanize_bytes should separate the numerical value and unit by a space, according to international standards.

The kind of space should be passed as an argument.

Examples of what you may want to pass as a space argument (non-exhaustive):

References:

https://en.wikipedia.org/w/index.php?title=Space_(punctuation)&oldid=1211874527#Unit_symbols_and_numbers

The International System of Units (SI) prescribes inserting a space between a number and a unit of measurement […]

https://en.wikipedia.org/w/index.php?title=ISO_31-0&oldid=1193092792#Expressions

Numerical value and unit symbol are separated by a space. […]

straight-shoota commented 6 months ago

Adding an option to configure a space between value and unit sounds like a good idea.

There are good practical reasons to skip the space in an environment where machine readability matters. Grepping formatted numbers is much easier if you don't have to account for (variations of) whitespace, for example. So I'd prefer to leave the current behaviour as default. Also to avoid disruptions.

It might make sense to have a simple value like true to indicate having a space. With this option, callers won't have to worry about the details what specific kind of space to use and just say they want the default space. I think the default should be a non-breaking space to avoid inconsistencies around line breaks. Whether thin or normal could be up for debate.