-
Notifications
You must be signed in to change notification settings - Fork 19
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
ACP: New Macro - debugging with clean input and clean output. Simultaneously. #125
Comments
The original However, that one was not accepted, and instead a simpler one was (rust-lang/rfcs#2361). That suggests to me that having more options for this aren't desired, and the expectation is that either you use |
What about if we use |
Note that implicit arguments were added a while ago to println! |
No, actually. Because the most common way that would be used is as |
Proposal
Problem statement
Why should the user have to choose between messy input and messy output? My proposed macro will enable the user to debug their code with clean input and clean output.
Motivation, use-cases
###Short motivation:
If you want to debug, you're currently forced to choose between writing long boilerplate and having messy output that requires more effort to visually navigate. It's important to be able to produce clean and clear output without having to write long boilerplate, especially for beginners and intermediate-level users (I can't speak for advanced users though, since I haven't reached that level myself).
###Long motivation:
If we want to debug code, we have the following options available:
dbg!
println!
print!
eprint!
eprintln!
As I understand it,
print!
andeprint!
are rarely used because the user can instead chooseprintln!
andeprintln!
to get the same thing but with clearer structure to more easily distinguish different outputs from each other (although there may be some use cases ofprint!
andeprint!
). Thus,print!
andeprint!
are suboptimal choices for producing clean & clear output with minimal boilerplate.println!
andeprintln!
produce clean and clear output, but they require the user to write long boilerplate.dbg!
can be used very concisely and easily, with minimal boilerplate. But the output is messy and takes more effort to visually navigate.Beginners and intermediate-level users (such as myself) may want to copy code examples from documentation and forums (like github) and paste them into their local environment (or Rust Playground) to play around with it, to better understand what the code actually does. Using
println!
andeprintln!
is cumbersome and messy to write, whilecfg!
is cumbersome and messy to read its output.I took the below code example from this page:
I tried to play around with this code for educational purposes, using two different approaches:
println!
anddbg!
. In both cases, I modified only themain
function as follows:println!
approachMessy input:
Clean output:
dbg!
approachClean input:
Messy output:
Solution sketches
Create new macro by adding the following code (or some variation thereof) into
library/std/src/macros.rs
:If you use my solution, the input and output should both be clean, as follows:
Clean input:
Clean output:
Links and related work
This issue is what triggered me into writing this API Change Proposal. I'm probably not the only one who would benefit from this proposed macro.
What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.
The text was updated successfully, but these errors were encountered: