I'm sure everyone who's used {:#?}
or dbg!()
has noticed...
Goto(
Address(
30016,
),
),
Label(
Address(
29990,
),
),
Expr(
Expr(
Expr(
[
Var(
0,
),
Const(
0,
),
Op(
Ne,
),
],
),
),
Address(
30016,
),
),
...It's not very pleasant to read. There's a lot of wasted vertical space.
Until a few years ago, I often used to do manual impls that write out the same thing as the derived would, but without DebugTuple to avoid the wasted space. But that's a lot of boilerplate and doesn't work for things like Option. After that, I developed the second most cursed crate I know of (after cve-rs): compact-debug, which literally patches the stdlib in memory.[1] With this enabled, the above data prints as:
Goto(Address(30016)),
Label(Address(29990)),
Expr(Expr(Expr([
Var(0),
Const(0),
Op(Ne),
])), Address(30016)),
which, in my opinion, is way more digestible. Despite its cursedness, I've found myself using compact-debug in almost every project I've done since, it's just so much better.
So, with the background out of the way. Is there any possibility to change this in a future version? And has there been any past discussions on similar topics?
Code-wise, the changes are trivial: just remove the is_pretty
checks from DebugTuple and it works out fine.[2] I would be happy to make a PR for this, should people be in favor. No idea how a change like this would work with stability attributes and the like, though.
The bigger problems are the ecosystem effects: first of all, would this change be desirable at all? I think it very much is, I find dbg!() almost unusable without it, but opinions may differ.
Second, does the ecosystem depend on the formatting? Debug
does explicitly state that the exact output format is not stable, but I would be surprised if there aren't a few test suites that check the exact formatting.
It's very much platform specific and a pain to maintain since the internal APIs and the compiled machine code have no stability guarantees. But that's beside the point. ↩︎
In my experience the DebugLists/Structs/Maps give sufficient vertical space to make it nice and readable for almost all workloads, with the exception of a few cases that resemble linked lists. ↩︎