Live data from Hacker News

Retiring a favourite C++ joke

ignition-training.com

71–80 of 151 posts

Re: Retiring a favourite C++ joke

#74
post #43

Do modern cars even allow you to step on the accelerator and the brake at the same time?

Why wouldn't they? The brake simply overrides the accelerator.

Sportier drivers may wish to brake and accelerate simultaneously (rev matching, weight transfer tricks). Normal cars just cut fuel when braking to avoid two-foot drivers burning their brakes.

Re: Retiring a favourite C++ joke

#76
post #43

Earlier quoted context omitted.

Why wouldn't they? The brake simply overrides the accelerator.

Sportier drivers may wish to brake and accelerate simultaneously (rev matching, weight transfer tricks). Normal cars just cut fuel when braking to avoid two-foot drivers burning their brakes.

The other use is for mere mortals to simulate differential lock when it is not there. I've used it couple of times.

Re: Retiring a favourite C++ joke

#77
post #68
post #38

I was surprised to see it not mentioned in the post -- the most obvious reason this joke should be retired is not the reference to a television show but rather the modern practice of never using new or delete at all in C++ code. Modern C++ avoids these pitfalls and I think it's been 10 years since I've written the words the new or delete.

> the modern practice of never using new or delete at all in C++ code What? How do you (de)allocate memory without new and delete? If the answer is "smart pointers" then why bother use C++ in the first place, just use Go or something.

You allocate either on the stack, or on the heap with make_unique and make_shared. Deletion occurs automatically once the object is out of scope.

Re: Retiring a favourite C++ joke

#78
post #68
post #38

I was surprised to see it not mentioned in the post -- the most obvious reason this joke should be retired is not the reference to a television show but rather the modern practice of never using new or delete at all in C++ code. Modern C++ avoids these pitfalls and I think it's been 10 years since I've written the words the new or delete.

> the modern practice of never using new or delete at all in C++ code What? How do you (de)allocate memory without new and delete? If the answer is "smart pointers" then why bother use C++ in the first place, just use Go or something.

Why would you respond to a comment about a topic you don't understand and spread false information? You clearly cannot tell the difference between garbage collected language and smart pointers.

Re: Retiring a favourite C++ joke

#79
post #68
post #38

I was surprised to see it not mentioned in the post -- the most obvious reason this joke should be retired is not the reference to a television show but rather the modern practice of never using new or delete at all in C++ code. Modern C++ avoids these pitfalls and I think it's been 10 years since I've written the words the new or delete.

> the modern practice of never using new or delete at all in C++ code What? How do you (de)allocate memory without new and delete? If the answer is "smart pointers" then why bother use C++ in the first place, just use Go or something.

Go is a garbage collector. Smart pointers are not.

It's fairly simple:

instead of new --> make_unique(); this returns a pointer, but it will automatically delete its memory when it goes out of scope.

instead of delete --> do nothing; the memory is deleted when you don't need it any more.

There are additional API methods on the unique pointer that allow you to do other things for flexibility, but while continuing that memory safety.

This is nothing at all like a GC language like Go.

Re: Retiring a favourite C++ joke

#80
post #66
post #38

I was surprised to see it not mentioned in the post -- the most obvious reason this joke should be retired is not the reference to a television show but rather the modern practice of never using new or delete at all in C++ code. Modern C++ avoids these pitfalls and I think it's been 10 years since I've written the words the new or delete.

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.
Post reply on HN