Project

General

Profile

Actions

Feature #18410

open

Proposal to make inspect include underscores on numerics

Added by brightbits (Michael Baldry) about 3 years ago. Updated about 3 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:106701]

Description

The documentation for inspect reads "Returns a string containing a human-readable representation of obj." but for large numerical values, while 964218442 is human-readable, 964_218_442 is a lot more readable. The language allows the use of underscores to make numbers more readable, so why should inspect not also honour this?

Happy to provide a patch if this would be an acceptable change.


Related issues 2 (1 open1 closed)

Related to Ruby master - Feature #16011: Digit groupingRejectedmatz (Yukihiro Matsumoto)Actions
Related to Ruby master - Feature #17339: Semantic grouping with BigDecimal#to_sAssignedmrkn (Kenta Murata)Actions
Actions #1

Updated by mame (Yusuke Endoh) about 3 years ago

Updated by mame (Yusuke Endoh) about 3 years ago

Thousands separators may vary depending on locales. See the discussion of #16011.

Even if we can come to an agreement on the spec, changing Integer#inspect may have a big impact. We need to estimate the impact of the incompatibility. It would be good to first implement and try it with some projects like Rails.

Updated by duerst (Martin Dürst) about 3 years ago

mame (Yusuke Endoh) wrote in #note-2:

Thousands separators may vary depending on locales. See the discussion of #16011.

Yes indeed. The advantage of using 964_218_442 is that a) I don't think there's actually a locale that uses this convention (but I may be wrong), and b) this is the form that Ruby uses in source.

Updated by sawa (Tsuyoshi Sawada) about 3 years ago

In agreement with mame's comment, even if we can come to an agreement on the spec, I think it should be a property of pretty print rather than normal inspection. If there is need to make the numbers particularly readable to human, in such situations, pretty print should be used. To me, separating array or hash elements with space characters (i.e., what pretty print does) looks very similar to separating numerical digits with separators.

Changing pretty print would probably have less impact than changing inspection, and also there might be room for locale/string format configuration.

Updated by brightbits (Michael Baldry) about 3 years ago

mame (Yusuke Endoh) wrote in #note-2:

Thousands separators may vary depending on locales. See the discussion of #16011.

Even if we can come to an agreement on the spec, changing Integer#inspect may have a big impact. We need to estimate the impact of the incompatibility. It would be good to first implement and try it with some projects like Rails.

As mentioned by Martin, I was proposing always using _, as you can in Ruby code, not any kind of locale specific one. Hopefully there would not be incompatibilities, as inspect is specifically meant for human readability, not by code, but I'll look in to applying this change against the Rails code.

Updated by brightbits (Michael Baldry) about 3 years ago

sawa (Tsuyoshi Sawada) wrote in #note-4:

In agreement with mame's comment, even if we can come to an agreement on the spec, I think it should be a property of pretty print rather than normal inspection. If there is need to make the numbers particularly readable to human, in such situations, pretty print should be used. To me, separating array or hash elements with space characters (i.e., what pretty print does) looks very similar to separating numerical digits with separators.

Changing pretty print would probably have less impact than changing inspection, and also there might be room for locale/string format configuration.

I think given the output of inspect is documented to be a human readable, it's not unreasonably to expect it to be so. I agree it would be nice for pretty print to do it but that doesn't have quite the same smooth experience of just getting nice readable numbers in IRB output by default.

Saying that, is there a mechanism where IRB output gets formatted differently that isn't via inspect, something more localised to IRB? That may be a less far reaching change with the same end result

Actions #7

Updated by mrkn (Kenta Murata) about 3 years ago

  • Related to Feature #17339: Semantic grouping with BigDecimal#to_s added
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0