-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use T#to_s instead of T#inspect for Array#to_s #5632
Conversation
Note that this behavior was copied from Ruby, so maybe there's a reason to it. But if we change this, we should change Hash too and check other places too. |
I'd rather revert suffixes in numbers. They are too noisy. |
So someone came saying they depended on the to_s output format of array and suddenly we have to changer things? Why on earth aren't we just saying "don't depend on to_s/inspect on array". |
I don't know, I can't decide this anymore. For me it's just noise. |
Nevermind, let's fix
|
I think that knowing the runtime type of something is a huge part of the inspect output. Inspect is largely used for debugging and knowing the type when debugging is hugely useful for reasoning about its behaviour. |
@bew would you want to include the rest of the containers in this PR? |
The failing spec shows a case that we are not analyzing. Maybe it's wrong to assume that there is a human (non-programmer) readable form of the containers, hence the current behaviour could be ok. |
@bcardiff yes, I can do that later today |
Yup, that's a good reason why Array uses inspect. Plus, Array is really for programmers, not a general output that you should be sending down the wire. I think there's nothing to do here: don't use |
Ok, just understood your comment @bcardiff, that's a good point. Let's leave it that way then. |
[1_i64].to_s
gave:[1_i64]
[1_i64].inspect
gave:[1_i64]
It was because
Array#inspect
usedArray#to_s
, with usesT#inspect
instead ofT#to_s
.Now
Array#to_s
usesT#to_s
&Array#inspect
usesT#inspect
:[1_i64].to_s
should give:[1]
[1_i64].inspect
should give:[1_i64]
This 'correct'
to_s
/inspect
use could also be ported toTuple
,NamedTuple
,Set
,Hash
,Range
, and some others, but at leastArray
is done. I think it is the more important as it is usually used to print it's elements (not only for console debugging purpose).