CppCon 2017: Dietmar Kühl “The End of std::endl”

preview_player
Показать описание


Lightning Talk


*-----*
*-----*
Рекомендации по теме
Комментарии
Автор

A nice short video I can send to everyone who is stubborn as hell... =)

Broekmanium
Автор

Why not deprecate it? It is clearly badly named. Just replace it with something like std::nl or std::newl or std::newline and let intend match the outcome. To have the same functionality an std::flushl or std::flushline can be introduced as well.

YourCRTube
Автор

I think the name is a big reason why it gets misused, nowhere in the name "endl" does it even hint that a flush is involved.
Maybe std::endl should be changed to just be adding the line break of the current OS (be it \n or \n\r), and a new std::endlflush should be implemented that does what std::endl is doing right now (\n with flush).

kyoai
Автор

I don't get why it is easier to some people to write "std::endl" instead of '\n'...

jankodedic
Автор

The end of endl ? Surely not.
Like with each io stream, console output has to be flushed in order to force emptying the internal stream's buffer.
Thus, it is clear that endl manipulator, which intends to "end the line output" does not simply add a new line character, but also flushes the stream to output it. This is not new at all.
Performance considerations ? Only if you actually output thousands of lines to a text file or to console.
In over 30 Years of C++ programming experience, i never ever needed to do that. So what ?
Usually, i do mix \n and endl, like most developers i know. For example, if you create a lengthy sql string containing line breaks, you will use \n, but at the end of this, the complete string will be output with endl, so that you can be sure to empty the buffer. If you skip that, you might end up with incomplete lines, missing data.

I urge such self-proclamed code gurus to stop the habit to set up killer statements like "Never ever do this, always do that". Better say "Consider this, because that one may have some drawbacks". It always depends on your intention what you do.

gerhardbiebl
Автор

std::endl concisely expresses what a lot of programmers want when they would've written printf("somethnig\n") or puts("something"). In C we were used to a line-buffered version on interactive terminals (which was automatically fully buffered if it wasn't interactive IO). I personally understand std::endl does a newline followed by std::flush, I haven't seen people misuse std::endl too much but then again I haven't seen a lot of code relying heavily on iostream. I feel like instead of educating people on what's happening, which it does manage to some extent, this lightning talk gives the wrong message. I can't wait for someone to 'correct' me on using std::endl, what a brilliant new waste of time I've got. Can we start teaching people about misunderstandings without relying on weird fear-mongering tactics and new things to 'avoid'? The hot tap can burn you but that doesn't mean you should always use the cold tap and then the radiator to warm your wet hands.

ChrisPowa-
Автор

I already knew this, by the Jason Turner presentation, some years ago.

MrAbrazildo
Автор

The whole _iostream_ package is a hot mess of multiple responsibilities, problematic statefulness, and hacks. I have despised it from its inception.

JiveDadson
Автор

Those who care about performance don't use iostream anyway.