Convenient debug printing

Per Nordlöw per.nordlow at gmail.com
Fri Feb 1 15:49:24 UTC 2019


Rust just added a standard macro `dbg` for debug printing

https://blog.rust-lang.org/2019/01/17/Rust-1.32.0.html#the-dbg-macro

What's the closest match for this macro we can get with D?


I have put together a similar solution at

     
https://github.com/nordlow/phobos-next/blob/master/src/dbgio.d#L51

used as

     int x = 42;
     dbg("x: ", x);

printing

     dbgio.d:68: Info: x: 42

but it only works with a cumbersome writeln-syntax.


I also have

     
https://github.com/nordlow/phobos-next/blob/master/src/dbgio.d#L12

copied from Wilzbach's effort and used as

     int x = 42;
     int[] y = [42, 43];
     mixin dump!("x", "y");

printing

     dbgio.d:17: Info: x: 42, y: [42, 43]

but, of course, cumbersome in another syntactic way.


Is this as good as it gets in D with regards to syntactic 
sugarness?


More information about the Digitalmars-d mailing list