-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Description
Hello!
I have to say I don't love the dbg!
macro. It pollutes the output unnecessarily, and could easily be way cleaner.
Personally, I think it is a missed opportunity. It actually doesn't use debug formatting {:?}
, it uses alternate debugging {:#?}
I'm not sure why. This, unfortunately, makes everything get a lot more newlines than needed. So, we get this:
[src/lib.rs:105] &order = [
8,
14,
13,
]
[src/lib.rs:105] &order = [
6,
14,
5,
4,
3,
2,
]
[src/lib.rs:9] &win = [
8,
14,
13,
]
instead of simply this:
[src/lib.rs:105] &order = [8, 14, 13]
[src/lib.rs:105] &order = [6, 14, 5, 4, 3, 2]
[src/lib.rs:9] &win = [8, 14, 13]
Similarly, for structs it prints one field per line and gets very verbose.
I imagine people use the alternate formatting very sparingly, only when something gets so complex that it warrants the added pollution, I know I rarely have used it. In the vast majority of cases, we all use {:?}
the standard debug formatting. So, why adopt the alternate one in the dbg!
macro?
I'd like to ask you to please reconsider it. It is a single character change.
Thank you.
rust/library/std/src/macros.rs
Lines 365 to 366 in 25283f4
$crate::eprintln!("[{}:{}] {} = {:#?}", | |
$crate::file!(), $crate::line!(), $crate::stringify!($val), &tmp); |