"Programming in C++ is premature optimization"
does everyone do some people say this?
People often say this (somewhat tongue-in-cheek, in my experience) as a dig against C++ as a choice of language. People typically choose C++ because it is, in most cases, faster than an alternative like Python or Java. However, most of the time, the additional speed gained is not really needed. When a person says "Programming in C++ is premature optimization" they are saying that you could have programmed your application in some other language, been done much faster, then if you needed to make some part of your code really fast, you could simply code that part in C++ and call that routine from the other language.
Because they don't know how to program in C++.
Generally speaking, such people simply don't understand how to program safely (and quickly) in C++ and suggest that doing so takes up an inordinate amount of time or somesuch rubbish. If it really was significantly slower, then people would only do it to make their programs run faster, as C++ is easily the fastest mainstream language. That would make it an optimization- "I'd rather program in C#, but I have to use C++ because it's faster.", and usually premature because most optimizations are.
However, this is usually ignorant. C++ hasn't been a hassle to program in since
std::vector were invented.
Edit: Sorry, I wasn't sufficiently clear. I forget when speaking to non-C++'ers how little they generally know about the language, as I usually just stick in the C++ channel on SO. First,
shared_ptr is hardly the only smart pointer, I use
unique_ptr a lot more often, and Boost has more. Second, garbage collection is nothing like
shared_ptr. Try to garbage collect GPU memory, or a file handle, or a database connection, or an HWND. Good luck. Third, the customizability of
shared_ptr is vastly above what you can get from a garbage collected system. Recently, I replaced my memory allocations with a memory arena allocator that I wrote myself. It was like, a hundred lines of code and an hour to test. But I didn't have to re-write a single line of my shared_ptr code, because I just dropped in a custom deleter and it just worked. Try replacing your allocator or inventing a new smart pointer in C# or Java and tell me how long that takes. Oh wait, if you look at
using, then even special language power can't make another kind of resource management work in C#. If garbage collection doesn't suit your needs, then you're screwed. That's not my definition of a higher-level language.
Now, I'll be the first to admit that I'm not on the cutting edge of languages like Python, Java, or C#. But as far as I know, Java and C# have nothing as strong as templates. Java's generics are hardly good for anything, and C#'s aren't that much better. For example, I use an expression template to automatically generate a finite state machine. I've never seen anything like that. If I was coding in Java, I'd have to code it manually.
I haven't used C++ in a long time (and never templates), so this is from memory based on other questions on Programmers.SE and on StackOverflow:
Templates are handled at compile time, and C++ allows you do do some crazy tricks with complicated ones.
Because they're handled at compile time instead of runtime, all that execution is "optimized" away, leading to compiled code that could in some cases be faster than C, because the optimizations done are complicated and hard to to by hand.
And it's "premature" optimization because this is done before any testing for speed ;)
If anyone with experience wants to add/fix what I remember, please do. Don't just downvote.