aka “bros: in order to be rich, just don’t be poor.”
To be clear, he’s not saying “just code better”, as the title implies. It’s a really poor choice of title.
you are going to mess up somewhere and get leaks, stray pointers, etc. This is true independently of how conscientious you are with your allocations:
He goes on to say, effectively, “Don’t use new/delete/malloc/free if you can help it. Use smarter mechanisms.”
No, this is kinda right. Memory leaks =/= memory safety. Memory leaks are just when you keep allocating more and more memory, and can be done in any language. If I make accidentally make a list that infinitely grows in python, that’s a memory leak.
There are techniques to write code that is mostly free of leaks, which is what he is referring to.
Memory safety, on the other hand, doesn’t seem to be mentioned on that page…
A reminder that Bjarne doesn’t actually code. He is a bureaucrat.
lol “jUst wRiTe bETteR cOde”

The memory leaks section just feels like an introduction to smart pointers as though they’re some complex concept. Also, the page is showing its age by mentioning the now-removed
auto_ptrinstead of something likeunique_ptr.Anyway, scrolling down a little more:
Why can’t I assign a vector<Apple*> to a vector<Fruit*>?
This actually comes up in C# with arrays. Copying their example here:
object[] array = new String[10]; // The following statement produces a run-time exception. // array[0] = 10;It may have been a design mistake not to make C#'s arrays invariant, though I don’t know the state of that debate today.
all these newfangled languages with their “memory safety” and “helpful tooling”, pah. all a real programmer needs is a hole punch and a roll of paper.



