Live data from Hacker News

Retiring a favourite C++ joke

ignition-training.com

131–140 of 151 posts

Re: Retiring a favourite C++ joke

#131

Earlier quoted context omitted.

No, I don't think it's a joke. It's just that when your counter is limited to values of 0 and 1 only, you can optimize it so heavily it almost looks like a different thing entirely: binary semaphores are usually called mutexes, but they're still semaphores.

Please show me the counter in std::unique_ptr :-)

Since that counter can only have two values, it's storage is optimized and merged with the underlying raw pointer itself (not unlike Rust's null pointer optimization for enums): non-null value of the underlying pointer also serve to represent the counter's value of 1, and the null value serves to represent the counter's value of 0. The check to not under-decrement, for example, manifests as the null check before calling the deleter on the underlying pointer.

Re: Retiring a favourite C++ joke

#133

It's an OK C++ joke, but not great. I could certainly give the author a few pointers...

Narrator: It's at this point Michael realized the futility of C++ and promptly learned Rust over a couple of beers pondering if he will ever survive the oncoming AI apocalypse.

Re: Retiring a favourite C++ joke

#134

Earlier quoted context omitted.

Please show me the counter in std::unique_ptr :-)

Since that counter can only have two values, it's storage is optimized and merged with the underlying raw pointer itself (not unlike Rust's null pointer optimization for enums): non-null value of the underlying pointer also serve to represent the counter's value of 1, and the null value serves to represent the counter's value of 0. The check to not under-decrement, for example, manifests as the null check before call…

Sigh, I saw this coming. By this definition, every C++ object with a (non-trivial) destructor would be "reference counted". Sorry, but I am not interested in playing word games.

Re: Retiring a favourite C++ joke

#135
post #127
post #126

Earlier quoted context omitted.

Now search for C arrays and strings, old style enums, str...() and mem...() functions, C style casts, preprocessor macros,..

That’s called whataboutism.

Nope, it is called experience with large code and teams.

Re: Retiring a favourite C++ joke

#136
post #135
post #127

Earlier quoted context omitted.

That’s called whataboutism.

Nope, it is called experience with large code and teams.

We are talking about one very specific issue, the point of this thread is a joke about new and delete. And your response after evidence services against your position is, “what about all these other things?” Definition of whataboutism.

Re: Retiring a favourite C++ joke

#137
post #80
post #66

Earlier quoted context omitted.

I frequently work with companies that have old, large codebases. A key requirement of the training in that environment is that attendees are able to read existing production code. In some cases that's over twenty years old and millions of lines of code. new/delete is just part of that reality. We teach them without encouraging their use.

That's perfectly reasonable. I have fortunately worked on greenfield projects, so don't have to contend with legacy paradigms.

Absolutely. I would also not use new/delete in that situation. It would depend on the audience whether they were still taught on a course, sometimes there is, and sometimes there isn't an educational purpose.

Re: Retiring a favourite C++ joke

#139
post #3

We are all getting old. College age kids aren't old enough to remember when that show was on the air.

I am also 29 and I'm old enough to remember Dawson's Creek, but I don't watch a lot of TV so I've never seen it.

If you find yourself with the time, and the inclination, give Arrested Development a go. I thought it was fantastic. I think there is a reason that it always sat a little under the radar. You have to actively watch it. It's not suited to being on in the background.

Re: Retiring a favourite C++ joke

#140
post #15

There's dozens of people who would get it... DOZENS!

yes, I would have thought the "better" version would be int tobias[24]; delete tobias;

I'll be honest, I didn't get it at first. I thought initially that it was too complex for the teaching example. And then it clicked. You're rather smart aren't you! I guess 24, or 36, or 48 would have worked!
Post reply on HN