4 ms·
I like and use C++. It fits my requirements of allowing high performance but still having rich abstractions. I also like most of the additions in C++11, and I l
by scott_s 15y ago
I like and use C++. It fits my requirements of allowing high performance but still having rich abstractions. I also like most of the additions in C++11, and I look forward to using them.
But, there is a valid argument for using a newer language that has nothing to do with the language itself: the ancient include, compile and link process. Having to do the #ifndef/#define/#endif dance in every header file I write is a reminder of this fact. That hack exists because 40 years ago, there was no concept of package management. I feel the same way when I get linker errors that require me to unmangle my class names to figure out what's visible where.
- munificent 15y ago> Having to do the #ifndef/#define/#endif dance in every header file I write I'm just using "#pragma once" in my current hobby C++ project. I understand pragmas are living in sin, but is there any reason I shouldn't use them?
- marshray 15y agoI wouldn't use "#pragma once", but it's also a straightforward thing to change later. If that turns out to be the only thing you need to refactor away from later as the project evolves, you're doing great.
- scott_s 15y agoIt's not part of the C++ standard, so you're relying on a compiler extension. In theory, your code could blowup if you tried a different compiler, but in practice, most compilers you would use implement it. In general, pragmas are for compiler extensions - that is, things not defined in the language spec.
- Arelius 15y agoNot really anymore, it's supported on most compilers these days. But that's only been the case as of pretty recent. The same could probably not be said if you were writing C instead of C++.
- rbrown46 15y ago#pragma once aside, I agree that not having to worry about writing and including headers at all is a significant improvement of Go over C++.
- cpeterso 15y agogcc 3.x had #pragma once bugs related to symbolic links. MSVC had bugs related to filenames that only differed by case. Modern gcc and MSVC can recognize and optimize for the #include guard pattern. Many benchmarks show no build time improvement of traditional #include guards vs #pragma once. I some one benchmark where the developer #included all his headers and source files into a single .cpp file. Compiling this single .cpp file was about 50x faster than a traditional build! <:) Of course, you will likely have name and dependency conflicts.
- kaffiene 15y agoWhile I understand the historical context behind wanting to maintain the ability to link to C code, I personally think that keeping the C include and link process was one of the more bat-shit insane things they did with the C++ language. It was an outdated concept when C++ was made and they should have had the courage to do better. Plenty of languages can interface with C without requiring the same brain-dead build cycle.