Re:Pointer Free Programming and the Future of Nim
by tomsmeding on Friday October 20, 2017 @02:45AM
(#15513936)
The only difference being that in the case of a smart pointer, you can't ignore the possibility of a null by accident.
[ Parent
| on HN ]
Re:Pointer Free Programming and the Future of Nim
by civility on Friday October 20, 2017 @03:36AM
(#15514124)
You can easily ignore null by accident while using smart pointers:
struct foo { int bar; };
std::unique_ptr<foo> bug;
bug->bar = 123;
Re:Pointer Free Programming and the Future of Nim
by tomsmeding on Friday October 20, 2017 @03:42AM
(#15514148)
True, didn't think of that. Then indeed they are quite useless, and IIRC they are actuallt deprecated in C++17.
Re:Pointer Free Programming and the Future of Nim
by civility on Friday October 20, 2017 @03:54AM
(#15514195)
I don't agree they are useless - they don't stop you from accessing nullptrs, but they do help manage the lifetimes of your dynamically created objects.
And I haven't seen anything indicating unique_ptr is to be deprecated - maybe you're thinking about auto_ptr.
Re:Pointer Free Programming and the Future of Nim
by albinofrenchy on Friday October 20, 2017 @01:09PM
(#15517382)
Smart pointers are not at all useless and not at all deprecated (you are thinking of auto_ptr; there are still unique_ptr and shared_ptr).
They don't try to address the check for null problem at all; that isn't their intent. All they mean to do is eliminate several classes of common, easy to make mistakes such as not zero initializing or not freeing the resource.