-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: add eprint(ln)!
#1869
RFC: add eprint(ln)!
#1869
Conversation
I think there should be both I think the final name shouldn't focus too much on the “error” part. Yes, the output stream is called stderr, but it really just means “out-of-band” messages that are not part of the regular output. |
However, |
Adding only for dla_step in 0..NPARTICLE {
err!("Particle {:8} of {:8}: ", dla_step, NPARTICLE);
// ... long, time consuming computation ...
errln!("({:8.6}, {:8.6}, {:8.6}) ({:5?} ms)",
(pos.0).0, (pos.1).0, (pos.2).0, timer.last_ms()
);
}
That said, this kind of usage of stderr also conflicts with its typical designation as "a safe place to dump stuff"; if I added debugging output to methods called during that computation, it would mess up my nice output. In this sense, I would almost see a lack of |
I'm of the opinion that, whatever we call it, we should add it. I've reimplemented these macros in far too many Rust programs. |
I would also like to have this. Like @ubsan, I've written this macro a gagillion times. Some lightly held opinions:
|
Update: Rust should avoid introducing excessively abbreviated names, such |
On the name bikeshedding: I feel like |
I would rather see it be There's also a consistency or learning issue. We don't use What does the stdlib use for errors right now? Whatever it is, we should align the name with that. |
My objection to |
text/0000-eprintln.md
Outdated
|
||
It will, however, be necessary to add text to the reference manual and | ||
especially to the tutorials explaining the difference between "primary | ||
output" and "status reports", so that programemrs know _when_ to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: programemrs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, thank you.
I like @Havvy's suggestion of I think I'm slightly in favor of |
🚲 I like |
I dislike this strongly, for this reason: You aren't supposed to use I think |
@ticki Every command line program I've ever written has never needed to care about the performance of writing to I'm sympathetic to |
FWIW it might be a better idea to go with the |
Logging is pretty orthogonal to output designed for consumption by an end user. |
I can't say my experiences are the same. If you log extensively, you can easily severely slow down the program, whereas using Moreover, I would say that just throwing out some logs into That being said, this macro can be useful for debugging, but even then you rarely need to filter between stderr and stdout when you debug. |
@ticki It's pretty common for me to use |
My most common use case for |
There's nothing hacky about printing an error message to |
Please don't call it These would all be better, with my personal (weak) preference towards
|
Out of all the suggestions, I still prefer one from the internals thread: println!(stderr, "this happened: {}", err); Adding a variant to the macro that can be either |
At the risk of further bikeshedding: I prefer the forms that start with something other than @seanmonstar That looks appealing, but seems difficult to implement in a robust way. Do you intend |
Bikeshed: I prefer |
|
|
I fully second @dpc here. No matter the name we'll need to get used to it anyway, so I don't see much point in bikeshedding it to death. Let's just make it obvious that it's about printing to stderr. |
One vote for |
I will make time to do that if no one beats me to it. Where can I find the publication schedule for the book, so I can know when it needs to happen by? |
Here let me propose two more bike-shed colors 🚴♀️🚴.
I am actually skeptical that we cannot use #![feature(use_extern_macros)]
macro_rules! vec {
($a:tt) => { "no I'm not a vec :p" }
}
fn main() {
println!("{:?}", vec!(4));
println!("{:?}", std::vec!(4));
}
// std::vec! is fine, so why not std::error!? BTW, if users of most other languages can live without a dedicated print-to-stderr function, I don't see how we are escalating to a crisis here 😄. I don't hear people saying Python / Go / C# / Swift have bad ergonomics because you don't have a simple function to write to stderr.
|
Eh? To me this is the primary motivation! The inability of tests to capture stderr is a massive pain in the behind and leaves me constantly sprinkling around ...yet by that same token, I still ultimately agree with your conclusion. There should be more ways to write capturable output than through a macro; since macros cannot be passed around like files can, and are impossible to abstract over except through more macros. (well, okay, you can do some amount of abstraction with callbacks, but only so much!) To be honest, I'm not sure I understand why rust's |
And in the discussion in #1561, one concern was about spurring use of the macro import/export system and demonstrating it was understandable and manageable. This seems like a perfect job for that (and I'm a fan of this syntax). |
Thank you @zackw! Basically as soon as this stabilizes... we don't have any hard dates yet, it's just "as soon as everything gets done". See all the states the chapters have to go through and which chapter is in which state (be sure to scroll to the right), chapters 2, 3, 4, and 6 are supposed to be pretty much "frozen" right now with only small changes (I hope this to be a small change) since they'll be going through layout soon. |
I was about to propose |
|
Can we reuse |
CAUTION We may create very short name, but only for very useful use cases. Per kennytm's comment above, many other languages don't have short name for this use case (i.e. writing to stderr).
|
@liigo A program should print only a direct result to |
Ok the libs team convened today and we discussed this RFC. Overall there definitely seems to be broad agreement to the functionality of these macros and the question was the name. Of the many many names proposed here we've decided to stick with the original proposal, Thanks again for the RFC @zackw! |
Tracking issue: rust-lang/rust#40528 |
Add `eprint!` and `eprintln!` macros to the prelude. These are exactly the same as `print!` and `println!` except that they write to stderr instead of stdout. Issues rust-lang#39228 and rust-lang#40528; previous PR rust-lang#39229; accepted RFC rust-lang/rfcs#1869; proposed revision to The Book rust-lang/book#615. I have _not_ revised this any since the original submission; I will do that later this week. I wanted to get this PR in place since it's been quite a while since the RFC was merged. Known outstanding review comments: * [x] @steveklabnik requested a new chapter for the unstable version of The Book -- please see if the proposed revisions to the second edition cover it. * [x] @nodakai asked if it were possible to merge the internal methods `_print` and `_eprint` - not completely, since they both refer to different internal globals which we don't want to expose, but I will see if some duplication can be factored out. Please let me know if I missed anything.
Add `eprint!` and `eprintln!` macros to the prelude. These are exactly the same as `print!` and `println!` except that they write to stderr instead of stdout. Issues rust-lang#39228 and rust-lang#40528; previous PR rust-lang#39229; accepted RFC rust-lang/rfcs#1869; proposed revision to The Book rust-lang/book#615. I have _not_ revised this any since the original submission; I will do that later this week. I wanted to get this PR in place since it's been quite a while since the RFC was merged. Known outstanding review comments: * [x] @steveklabnik requested a new chapter for the unstable version of The Book -- please see if the proposed revisions to the second edition cover it. * [x] @nodakai asked if it were possible to merge the internal methods `_print` and `_eprint` - not completely, since they both refer to different internal globals which we don't want to expose, but I will see if some duplication can be factored out. Please let me know if I missed anything.
I know this is a done deal but I'd like to very briefly present my thoughts against it- Given that stdin/stdoout/stderr are unix file descriptors, including this in standard rust library with very specific use is not a "rustic" way of handling things. I personally think the right way would be that we have multiple streams: Out, trace, debug, warn, error and at the start of a program the runtime initializes (or user manually) each based on what file descriptors are provided by the OS/shell. So on windows console, where only one stream is available, all these would go to I'm not trying to start a flame war and I'm typing this on Unix myself but let's face it, these streams were designed when there was no GUI. The reason rust works is because rust has thrown out all "conventional" wisdom and starts with 0 baggage. I think a 0 baggage here would be having an option to have multiple streams. I haven't given too many details/some inconsistent details but I can flesh out more in the off chance you guys might be interested in thinking about it. |
@SRGOM: I've seen this in Powershell, and I dislike it. It really complicates things, for no good reason. |
Continuing discussion from https://internals.rust-lang.org/t/extremely-pre-rfc-eprintln/4635/7 and rust-lang/rust#39229.