One of the main reasons to use C++ today is the potential for high performance. One of the examples given is a great demonstration of what not to do: allocate a new container on the heap, scan it once, and delete it. I'm talking about the "I in team" example, which if you coded it by hand would almost certainly use a better algorithm. It's hard enough teaching people to avoid inefficiency when it's right there in front of them, and harder still when you encapsulate inefficiency in a pretty package. This is why some "obvious" functions don't exist in the STL.
I write performance critical software for a living (industrial image recognition) and I often try to squeeze the last few percent out of an algorithm. But even in my case the by far largest part of code I write is not performance relevant at all. And there I prefer terseness and readability over performance. Yes, there can be some cases where I have to switch to a more efficient version later, because profiling shows a bottleneck where I did not expect one to be. But in my experience this has never been too big of a problem to sacrifice readability from the beginning in all places.
I wasn't discussing readability, but rather performance. The two are not mutually exclusive. Nor was I picking on the "last few percent" of performance--the shortcoming in speed of the "I in team" example is likely an order of magnitude or more. And it isn't fixable without modifying the API.
Your comment reminds me that, from the other direction, those who make arguments for the performance of functional languages like Haskell often give example code that doesn't look very "functional" at all.
One sentence that comes to mind is "If you write C++ like you write Java, you are unlikely to see any benefit."
How is a profiler going to help if your code is riddled with inefficient structures? The "I in team" example can be made more efficient if SplitWords returns an iterator, but SplitWords itself won't be possible to change once it is ingrained in a codebase (because e.g. some call sites will come to depend on it returning a list).
I love profilers as much as the next person, but if you build a system from inefficient building blocks, you may eventually need to build it again. But in a professional setting you are likely to be told not to do build it a second time, or you will be gone before that time comes, leaving someone else to clean up your moribund codebase of a thousand inefficiencies.
I hear a lot of people complain about higher levels of abstraction in languages like C and C++, because they take away control or don't allow them to squeeze every last drop of performance out of their programs.
I also see a lot of software in the wild that was programmed in C and C++ and runs very fast... but is buggy as hell or has pretty nasty security bugs.
The fact is that, regardless how good you think you are, most likely you're not one of the few people who can write fast, bug-free[0] software in C and C++. I certainly am not despite having written quite a bit of C and C++ in the over the years. The amount of high-impact bugs (especially security bugs, eg Heartbleed)
[0] Where I really mean: no severe bugs (data corruption, data loss, security flaws)
What you say is somewhat true most of the time when you are writing an application. However, when I am writing a library I have far less control over situations where functions in that library will get called. So it makes sense to make the library lean and lacking obvious bloats, or at least make efficient code paths possible without forcing the application programmer to indulge in excessive verbosity. This makes the library more broadly usable.
As an application developer its a big pain to realize that the library that you have built your application around now needs to be incised out for performance reasons. In theory, if you design your interface well one can switch out libraries, but it is rarely as clean as what theory claims. Interfaces set, if not in stone, at least in in loose concrete, the data-structures that are convenient to use.
EDIT: I hasten to add that I am not complaining about the library, far from it.
> it makes sense to make the library lean and lacking obvious bloats, or at least make efficient code paths possible without forcing the application programmer to indulge in excessive verbosity.
Does not apply to these people:
> It's hard enough teaching people to avoid inefficiency when it's right there in front of them, and harder still when you encapsulate inefficiency in a pretty package.
who, by definition, are not experienced enough to write code that is sufficiently lean and lacking obvious bloat, or at least make efficient code paths possible. If they were, then they won't have a problem with the pretty package either.
Oh, I know - it was from the post which you replied to.
I only wanted to point out that in the context of the comment you replied to, I didn't feel that those were the people who should be worrying about optimised code.