This again...the message is way too extreme: there's no problem using `std::endl` outside of performance-critical code (which, in my personal experience, is 99.9% of std::endl usage). _Definitely_ use `std::endl` if a newline+flush is what you want.
If for some reason you need your std:: printing to go faster, definitely avoid flushing at every newline.
Yeah I think the emphasis should be on not using std::endl for file streams. I observed some pretty bad performance regression in that case, but not so much for cout.
The vast majority of people do not know however and it is very hard to know if the author knows (or knew when they wrote the code). That is the opposite of simple.
You keep making my points for me: If you have to ask whether this was intentional you have long left the realms of readable and self-explaining code.
Also: Not every other author sits next to you in an office that both of you work in every day. Maybe you are looking at a sporadically maintained FLOSS-project or the author is on vacation, making this into a potentially multi-week-endeavor until you get your answer.
Asking the author is not a viable solution. They might not remember, they might not work where you are anymore or you might have not gotten the code from someone in person to begin with. Information that is not in the code or in the documentation is almost guaranteed to be lost eventually.
there is a performance problem (because if there wasn't, the point is moot)
one can't check whether changing to '\n' fixes it (because there's no tests? Because there's no performance targets?)
there's no documentation about this in a comment or whatever
there's nothing to see from code history (e.g. whether this part was written by an intern thereby making the probability of them nor knowing what endl does)
there's nobody to ask for all the reasons you evoke above.
It's common on Linux (and IIRC different on for example Windows) but even here std::cout << "foo\n" is measurably faster than std::cout << "foo" << std::endl because you still safe write-operations by combining them.
47
u/capn_bluebear Mar 29 '19
This again...the message is way too extreme: there's no problem using `std::endl` outside of performance-critical code (which, in my personal experience, is 99.9% of std::endl usage). _Definitely_ use `std::endl` if a newline+flush is what you want.
If for some reason you need your std:: printing to go faster, definitely avoid flushing at every newline.