6 ms·
Gee, another rant which can be summed up by "all abstractions are leaky". Congratulations for the insight, unfortunately it's not new, so not too interesting, b
by sgift 3y ago
Gee, another rant which can be summed up by "all abstractions are leaky". Congratulations for the insight, unfortunately it's not new, so not too interesting, but let's still dive into it.
So, smart pointers are leaky, so use normal pointers instead. If we ignored all the problems that normal pointers have this may even look reasonable. After all, if we have a leaky abstraction, maybe we could just use the non-leaky foundation? But pointers have problems. Use-after-free, double-free, memory leaks. All of this happen with pointers far more often. Which is a bit of a problem if you want to write reliable software.
Are smart pointers a perfect solution? No. Are they better than "use raw pointers everywhere, cause in some cases the abstraction provided by smart pointers will fail?". Well .. yeah.
- jamesTee49 3y agoThe point he was trying to make is the books for decade are mantra it as safe even though it is not. The new thing in this article rant is set a unique value before nulling and freeing allowing easier tracking of mysterious crash later. When I look thru hundreds of juniors code reviews with C++ coding, I have never seen one doing it (this is with Ivy Leagues or just Udemy/Coursera self-taught background). Even senior C++ devs dont do it. They either depend heavily on profile debugging tools or printf out at certain lines. It is a good article just maybe not for decades experience C++ coders or academically inclined one that dont do large production coding low level algorithmic much (their response is like yours not-perfect use-others-it-is-your-brain-problem)...in C++ (doing many API calls programming don't count...they are merely API programmers). Anyway, companies I worked with already migrated to rust and haskell/erlang to avoid this kind of C/C++ issues - same or even faster speed (some parts code in asm) and 100x times safer and more productive than just C++. C++ in 2023 is just badly hotch-patch up language - ugly, inconsistent, lack advanced features, even the so called biggest reason using: speed totally not match against zig/asm/even Java in some code implementation. At this point using C++ is mostly a laziness of programmers to record the existing "proven" C++ libraries a bit like Cobol - seen these conclusions over 20+ companies I audited across the world. A lot of time, when analysing using C++, it is fast if you measure specific execution timing but then fall apart and burn down the company with lawsuit-litigations when factor in bugs and debugging. Rust and Haskell and especially Erlang (Scala too) just steam-rolled C++ when you do total time (coding-execute-maintain-debugging). Whatsapp is good example of my case, you will never be able to create Watsapp with C++ in those short time and very limited resources - rather than just a couple of programmers for programming, you need a committee and specialized team internal and sometime external to do debugging in C++. C++ was designed for the 486-pentium era where bugs is not important but speed is. Today, just go buy a better hardware and charge end willing paying customers more (military/telecom/medical). C++ is just not worth it unless maybe you need to translate it into another programming language.
- lovelyviking 3y agoWell for me it looks less like another rant and more like some practical advice preluded with basic introduction: ‘ When trying to track down a ghost like crash, nuke all of the Smart Pointers in the code. Make them raw pointers and delete them when you know it is safe. Prior to the manual delete, put some unique values out there prior to the deletion and be certain to null out the pointer you just deleted. The unique values make it a lot easier to track down which pointer was actually the culprit. “ With modern attitude of putting ‘Smart’ in front of every primitive automat I usually expect dealing with two dumbs - automat itself and another dumb who is going to relay on it. The worse part about “Smart” solutions is that now I have to dedicate part of my life for exploring the realm of idiocy that was driving someone else who had made this particular “Smart” device/technology. Instead of learning how to shift gears in the car and shift them when I need it I need to learn how some builder of automatic gear was thinking “when it is better to shift gears when driver is dumb” . Then (since automatic usually never work as I wish) I have to do mumbo-jambo dance to make it shift gears as I wanted. Something that was done easily with manual stick already. Automatic works only when it is really perfectly done which is a rare case . So as a builder of automatic/smart solutions - be modest ! Leave “Manual’ option available. Just in case. The only thing I usually wish from “Smart” solutions is the option to switch this stupid thing off unless it really works perfectly but even then …
- Dylan16807 3y agoMaking them raw pointers is an enormous amount of work, and "delete them when you know it is safe" very likely is harder than finding the misuse of the smart pointers. > I have to do mumbo-jambo dance to make it shift gears as I wanted. You do not have to do that.