logoalt Hacker News

jjmarryesterday at 11:19 PM3 repliesview on HN

Open the C++ example up and the first thing I see:

```cpp std::cout << "Received ReportCoordinateFrameSettings" << std::endl; ```

Generally, I've heard `std::endl` instead of \n has bad performance because it forces the statement to print immediately. And because cout is guaranteed to flush anyways when the program ends, you're adding a delay for no reason.

I wonder if there's something I'm not seeing that led to them adopting this rule. e.g. "abnormal program termination" caused by the weapon blowing itself up circumventing a buffer flush?


Replies

aftbityesterday at 11:29 PM

This seems like an incredibly unimportant quibble... I would imagine they just used std::endl b/c that's what most random tutorials used in the 2000s and that's how the engineer learned. If you are printing a debug string, you probably don't care that much about perf in the first place.

show 1 reply
gavinraytoday at 12:22 AM

The modern C++ idiom is std::println() anyways...

https://en.cppreference.com/cpp/io/println

__dyesterday at 11:49 PM

For a long time, std::endl demonstrated that you were a proper C++ programmer, not some neckbeard C apologist. It wasn’t until C++ had „won“ that it became acceptable to use \n again.