Sorry, I'm going to be a bit harsh now.
There is a host of distinctive differences between garbage collection and reference counting. Yes, both are memory handling strategies. That's where the similarities end.
"Just slap it in a shared pointer" is never a good advice without knowledge what 'it' is or in what kind of system it exists in.
No, reference counting is commonly seen as a specific implementation of garbage collection. https://en.wikipedia.org/wiki/Garbage_collection_(computer_s...
> "Just slap it in a shared pointer" is never a good advice without knowledge what 'it' is or in what kind of system it exists in.
I agree, but it seems from their blogpost that they are not sure that their developers are able to handle the "mental overhead" of managing ownership, hence the simple solution of going for shared ownership everytime.
(btw, I re-read your post three times and could not find any hint of harshness !)
Shared pointers provide the reference counting, but reference counting alone hardly constitutes a garbage collector because it doesn't collect all of the garbage.
For example, shared_ptr:s alone do not automatically detect and collect cycles.
I wish more of these posts were honest and said "we picked X cause we think it's cool and we're gonna get paid to learn it". But they have to make up some convoluted explanation that sounds rational and acceptable instead.
Note: I haven't used C++ at all on any project larger than a single file.
C++ libraries that would be as recent as Rust libraries would certainly take things by value or reference so there would be no problems. I honestly don't know libraries with raw pointers in their APIs that aren't from the 90's or before; and I don't think you want to use those in a current product anyways.
Also, as others have pointed out, you can smart-pointerise everything, but still have problems with common tree and graph structures. Rust is rigorous. C++ isn't; I'm not aware of any mainstream compilers which even have the option to make use of bare pointers or unsafe casting or undefined behaviour into compiler warnings/errors.
How so ? it's not like you are using the Win32 or POSIX APIs in 2017 anyways
(I'm something of an outlier here, maintaining a big legacy MFC application that targets Windows CE, but I can't be the only one. One implication of this is that I'm using the Microsoft MIPS compiler with this banner, that's probably older than some of the readers here and certainly predates C99:
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
... but my point is that it's not sensible to say nobody's using the system native APIs in 2017!)The problem is not developing "legacy" apps, it's comparing the development and maintenance of "legacy" apps with apps that just get started being written today, for which the bare minimum is being cross-platform.
> Are there wrappers for things like dlopen()? posix_madvise?
Actually, yes, in a cross-platform way:
* http://www.boost.org/doc/libs/1_65_1/doc/html/boost_dll.html (does dlopen, dlclose, and so much more)
* http://www.boost.org/doc/libs/1_65_1/doc/html/boost/interpro... (advise() == posix_madvise if available)
> Filesystem ACLs ?
none that I know of :( though MS has a fairly decent "modern C++" API that covers WinRT: https://github.com/Microsoft/cppwinrt but I don't think ACLs are even available in WinRT
> COM
oh, yes: https://www.codeproject.com/Articles/5748/Introducing-Comet
I don't think "boost" is aiming at anything. If you have a good idea of a library (and a good implementation!) you can submit it to boost. It's more a big repository of libraries with a somewhat consistent coding style.
I mean, if you only view functions as being called for side effects, then yeah maybe. But if you're constructing a data pipeline, unique_ptr in and out makes a lot of sense.
In general, though, passing a unique_ptr around is a bit cumbersome as this requires calling std::move way too often.
Yes, smart pointers are nice, they alleviate you from a whole lot of manual memory management - but the programming model is still vastly different from what you would do in a traditional GC'ed language(such as Java or C#)
Having memory leaks in modern C++ is a sign of not keeping up with the established idioms. Saying that experienced C++ programmers are worried about memory leaks is bizarre.
After answering a question during a job interview, the interviewer says 'are you sure you're a "senior programmer?"'
[1] shameless plug: https://github.com/duneroadrunner/SaferCPlusPlus
... are you guys sure of your "experienced C++ developers" ? There's as much memory management in modern C++ than in GC'ed language: none. Create your objects with `make_unique` or `make_shared` according to what makes sense (or just enforce `make_shared` if you're really dubious of the coding abilities of your team but at this point you'll have problems whatever you do).