3 ms·
My feeling is that it's the amount of characters written. Used to be foo* x=new foo(). Now it's std::shared_ptr<foo> x=std::make_shared<foo>() It adds up, ev
by nikanj 4y ago
My feeling is that it's the amount of characters written.
Used to be foo* x=new foo(). Now it's std::shared_ptr<foo> x=std::make_shared<foo>()
It adds up, every line of code is three times longer than it used to be.
- johannes1234321 4y ago> Used to be foo* x=new foo(). Now it's std::shared_ptr<foo> x=std::make_shared<foo>() There's `auto` for that reason. No need to duplicate the info. And: In general code is read more often than written, and the variant with `make_shared` provides extra information on the purpose of the heap allocation. That first line with the raw pointer and new requires following all calls closely to understand the intention. (Aside from also handling the lifecycle, which would this be code which one would have to write elsewhere, your example is missing at least one `delete x` (and likely more handling, considering this being a shared, not unique, ptr)
- TheFlash 4y agoWhile I agree C++ is very verbose, I would argue that modern C++ reduces the amount of code you need to write. The full code above should be : foo* x = new foo(); if (x != nullptr) { ... } delete x; and the equivalent modern C++: auto x = std::make_shared<x>(); ...
- dvzk 4y agoI started using std::shared_ptr in every project in 2008. Isn’t it late to denounce the changes now? The state of most C++ codebases is infinitely better today compared to then, partly owed to the added descriptivity.
- deleted 4y ago[deleted]