Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uppretty print `Debug` of tuples, tuple structs and enum variants in a single line #1198
Conversation
liigo
referenced this pull request
Jul 10, 2015
Closed
core: fmt: debug builders pretty print tuple structs and enum variants in a single line #26874
nrc
added
the
T-libs
label
Jul 13, 2015
This comment has been minimized.
This comment has been minimized.
|
what if you have a type in the tuple that is printed in multiple lines? |
This comment has been minimized.
This comment has been minimized.
|
This RFC doesn't change that behavior. Tuples were printed in a single line
|
This comment has been minimized.
This comment has been minimized.
|
Perhaps pretty-printing should keeps more than one thing on the same line up to 80 characters or os. Python’s |
This comment has been minimized.
This comment has been minimized.
|
As I noted in the related PR rust-lang/rust#26874,
MyTupleStruct(MyStruct {
a: 1,
b: TupleStruct(MyOtherStruct {
foo: bar
}, 10, "hi", Thing {
baz: buzz
})
}, true, false, OtherStruct {
thing: "hi"
})An adaptive scheme like @SimonSapin's suggestion would be possible but a bit tricky since this stuff can't allocate. You could do it by pretty-printing fields first into a line and character counting |
This comment has been minimized.
This comment has been minimized.
arthurprs
commented
Jul 18, 2015
|
I'm fine as it is, I'm unsure if we can insert any adaptive behavior without redirecting inner #Debug outputs to a intermediate buffer (which one may argue is a nonstarter). |
This comment has been minimized.
This comment has been minimized.
|
I'm in favor of this since I ran into issues with debug printing myself (with code similar to this: http://is.gd/xbWb2l) The output is either an unreadable oneliner (at least with many opcodes):
or this bloated mess:
The proposed solution would make this look similar to the |
alexcrichton
assigned
sfackler
Aug 5, 2015
This comment has been minimized.
This comment has been minimized.
|
This RFC is entering its final comment period. |
sfackler
added
the
final-comment-period
label
Aug 13, 2015
This comment has been minimized.
This comment has been minimized.
ProtectedMode
commented
Aug 14, 2015
|
I agree with @sfackler that this rule would hurt readability in many non-trivial cases. I do not think that making these trivial cases more natural to read justifies making more complex types (in my opinion) much harder to read. Counting line lengths would not even solve this issue, and also add a lot more complexity. |
This comment has been minimized.
This comment has been minimized.
|
The @rust-lang/libs team has decided that, while there is something to be said for improving the readability of Debug output, the changes proposed in this PR do not address that issue sufficiently:
An adaptive scheme could be interesting, but will need a lot of work to figure out what we actually mean by "pretty print". |
liigo commentedJul 10, 2015
Currently,
println!("{:#?}", Some(1));pretty print output as, with newlines and indent:But I don't think it is pretty print: it's weird and ugly, no one write code like this. It is not a preferred code style also.
Some(1)itself, without adding newlines and indent, is pretty well.Tuples were already implemented, in 1.0 stable, to pretty print in a single line, without adding newlines and indents. So we should do the same for tuple structs and enum variants, for consistency.