←back to thread

178 points todsacerdoti | 3 comments | | HN request time: 0.675s | source
Show context
codeflo ◴[] No.26340405[source]
I’ve personally never encountered the particular misunderstanding the author dispels here, but I’m sure the post is written from bitter experience. On the one hand, I shouldn’t be that surprised: Unfortunately, programming in C++ is really brutal for people who would rather learn by example than by carefully reading documentation.

But on the other hand, my instinctive reaction is: Come on, is this really something that confuses people? emplace_back is all about constructing something in-place, which is exactly the opposite of moving it there! How can any professional programmer be 180 degrees wrong about the purpose of a function they use regularly?

What I want to say here is that C++ is really hard, and that there are a million subtle things that one simply has to look up instead of making educated guesses. I don’t think people appreciate this difficulty enough.

replies(6): >>26340522 #>>26340785 #>>26344462 #>>26345318 #>>26345544 #>>26346091 #
1. umvi ◴[] No.26346091[source]
> C++ is really brutal for people who would rather learn by example than by carefully reading documentation

As if the documentation/compiler implementations are otherwise perfect. Quick, does `std::condition_variable::wait_for` use a monotonic clock under the hood?

Here's the docs: https://en.cppreference.com/w/cpp/thread/condition_variable/...

You might think so based on the part that says:

> Note that rel_time must be small enough not to overflow when added to std::chrono::steady_clock::now()."

But I happen to know from actually using it, that not all implementations use a monotonic clock: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41861

This led to a rather dramatic time bomb bug in our code that only flared up when GPS (and therefore system time) was being spoofed to replay a specific scenario in the past.

replies(1): >>26349472 #
2. bombela ◴[] No.26349472[source]
wouldn't that be an implementation bug? Because waiting for a specific amount of time is not the same as waiting for a specific wall clock time to come.
replies(1): >>26349635 #
3. umvi ◴[] No.26349635[source]
Yes, it is an implementation bug. My point being that C++ can be brutal even for people who carefully read the docs.