4 ms·
endl is not broken, and does not need fixing. it's one of several ways to do things and this video is pointing out that its documented features may not be exact
by hellofunk 11y ago
endl is not broken, and does not need fixing. it's one of several ways to do things and this video is pointing out that its documented features may not be exactly what you want, and alternatives are available.
However, sometimes endl is indeed what you want. There is nothing to "fix" here, except maybe your attitude.
- stormbrew 11y agoI think there's a valid argument to be made that it is at least poorly named, and that naming has resulted in people using it wrong, including among people who teach the language and so compound the problem.
- arcticbull 11y agoAgreed, names are the first line of documentation. Having endl flush is like using single letter variable names, but maybe a bit worse since single letter variables make you go find where they were declared but this lulls you into a false sense of security. This violated the principal of least surprise enough that someone made a 10 minute long video on it :) It's really hard to blame the user this time.
- smitherfield 11y agoPeople not using descriptive names for the important stuff is probably my number one pet peeve. We're not on a VAX, bytes aren't precious, and we aren't naming terminal commands, keystrokes aren't either. And nowadays every editor has autocomplete, so there's really no excuse.
- arcticbull 10y agoThe great vowel shortage of the late 80s is finally behind us :)
- byuu 11y agoI don't see any reason why, in the few instances you actually intend to flush, you won't just say << std::flush. This will make it very clear that you intend to flush the output. And we should definitely be prioritizing the documentation of our intentions over shaving a few bytes off of our source code file sizes. It was weird to ever merge two unrelated functions into something, and then name it something as cryptic as "endl". Especially when the most common case novices would encounter this would be std::cout, where terminals will automatically flush text to the screen upon receiving "\n" anyway.