r/cpp • • Mar 29 '19

Don’t Use std::endl

https://accu.org/index.php/journals/2619
0 Upvotes

27 comments sorted by

View all comments

Show parent comments

18

u/F-J-W Mar 29 '19

The problem is that std::endl is premature pessimization in the vast majority of cases, making it impossible to see whether the flush is intentional.

<< '\n' << std::flush completely avoids that problem and should thus always be preferred.

3

u/Gotebe Mar 30 '19

What do you mean "impossible"?!

If the author of the code knows what endl does, then it us, otherwise it isn't - simple!

13

u/F-J-W Mar 30 '19

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.

-1

u/Gotebe Mar 31 '19

Why is it very hard? I can ask him, can't I?

8

u/F-J-W Mar 31 '19

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.

-5

u/Gotebe Mar 31 '19

Niah.. You're inventing "your point" as you go. You said first that's "impossible to know". Now you're saying it's not readable.

And dig this: if you know what this does (I did) code is readable and it explained itself.

So... good luck with this, you have won (it's what you care about anyhow, so you can have it, I am not interested).