Skip to content
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

clarify show doc strings #36076

Merged
merged 1 commit into from
Jun 1, 2020
Merged

clarify show doc strings #36076

merged 1 commit into from
Jun 1, 2020

Conversation

JeffBezanson
Copy link
Sponsor Member

fixes #36072

@JeffBezanson JeffBezanson added docs This change adds or pertains to documentation backport 1.5 labels May 29, 2020
base/show.jl Outdated
To customize human-readable text output for objects of type `T`, define
`show(io::IO, ::MIME"text/plain", ::T)` instead. To customize how objects
are shown inside containers, check the `:compact` [`IOContext`](@ref)
property of `io`.
Copy link
Member

@tkf tkf May 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice if we could simply say

Suggested change
property of `io`.
property of `io` in `show(io::IO, ::MIME"text/plain", ::T)`.

However, current situation is complicated because

  • non-vector arrays call 3-arg show and then fallback to 2-arg show, with :compact => true set.
  • vectors do the same but without setting :compact => true.
  • dictionaries and sets use 2-arg show.

Maybe it's better to be honest and say that there are some rough edges in show system with containers and there is no consistent way to control how items with custom items are shown. I do still think we should be using show(IOContext(io, :compact => true), "text/plain", element) consistently everywhere in 3-arg show of containers but it cannot block 1.5.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to reword this. We shouldn't think of it as controlling how your type is displayed inside a container --- that can never fully work, because it will always depend on what the container does. All you really need to know is "MIME type = human readable, 2-arg = parseable, compact = keep it short". For example, matrices call 3-arg show because they are themselves using a human-readable output format. But if some other container only has a parseable representation, then its elements will use 2-arg show.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All you really need to know is "MIME type = human readable, 2-arg = parseable, compact = keep it short".

Yes, that's the ideal situation. It'd be great if we can orthogonalize target reader ("machines" vs humans) and the compactness of the output. The reason why I suggested to add "in show(io::IO, ::MIME"text/plain", ::T)" was that I thought this paragraph was about human-readable format (as that's how it starts).

Copy link
Member

@tkf tkf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for documenting this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display of array elements seems to use ::Mime:text/plain in juia1.5.0-beta1
3 participants