3 ms·
This is the thing that always drives me nuts about C++: the compiler always trying to second-guess me, or me having to second-guess it. If I had wanted to spend
by notacoward 6y ago
This is the thing that always drives me nuts about C++: the compiler always trying to second-guess me, or me having to second-guess it. If I had wanted to spend time thinking about compiler internals I would have made that choice decades ago (after I actually did work on compilers a bit along with everything else). If I want low-level control to achieve best performance or efficiency, I'll just use C and be careful to avoid its deficiencies. Been there, done that, I'm actually pretty good at it. Then I'll link that with code written in a language that lets me express higher-level intent at a decent level of abstraction, which is impossible with the $#@! compiler in my face all the time.
- jfkrorkt 6y agoOn the other hand, it's basically impossible to write in C something as fast as Eigen, because it's exactly the compiler that gets into your face which can optimize away the intermediate layers of abstractions, in a way that would require 10 times the amount of code in C.
- notacoward 6y agoYes, there are specialized libraries for many things, and some of them even force use of a specific language. So by all means people should use those languages for those things. There are some pretty good Fortran libraries out there too. But that doesn't mean Fortran should be adopted as a primary language for every kind of task within a large company, and the same reasoning applies to C++. A general-purpose language that's full of pitfalls or requires lots of boilerplate even for simple things is not really a general-purpose language IMO.
- voldacar 6y agoWhich also means that is basically impossible to read some eigen code and mentally visualize the compiled asm. Though there are certainly situations where that doesn't matter, it can be quite annoying.
- ncmncm 6y agoIt just takes some practice.
- knorker 6y agoIn this case though the problem was trying to use a feature OP didn't understand. The straightforward naive code is also the best code, here. So it's not an example of what you describe. In fact at least on stl containers, and your own classes with such members, move semantics "just works". Rebuild the same c++98 code with c++11 and it just skips needless copies as part of the language, not implementation. And it's not about second-guessing. The confusion here is not about the compiler implementation. It's about the language.
- pjmlp 6y agoSame applies to C, unless one is using -O0.
- lenkite 6y agoWhy is C++ getting bashed ? The compiler didn't second guess anything here. If he coded as a newbie or programmer from another language without navel gazing too much, he wouldn't have run into this problem. He deliberately made his code more complicated and paid the price for it. Many times straightforward code is the best code. Value returns in C++ are already optimised, no need to add anything fancy.