4 ms·
- Yes, it takes a C++ expert to do C++ well. If you aren't an expert, you're going to screw it up. You'll either get mired in what I call "Fancy C++ Voodoo Magi
by jey 19y ago
- Yes, it takes a C++ expert to do C++ well. If you aren't an expert, you're going to screw it up. You'll either get mired in what I call "Fancy C++ Voodoo Magic" by over designing your code and doing weird template meta-programming without any real goal or just use the wrong idioms, or forget about some random subtleties.
- Sometimes you really do need to write systems software. In these instances, I'm still going to use C++. I won't claim that C++ is a great language, but at the end of the day, the benefits provided by C++ make it worth it. It would just be more footwork in C. Classes, RAII, STL, templates, type-safety are all worth it. But this is because I have already made all the mistakes and written lots of bad C++ that I'm now able to write clean, simple and elegant C++. I'd advise a newbie programmer against becoming a C++ expert. It's not worth the time and effort to learn all the stupid cases and to learn when to use which feature and to what degree to avoid falling into the swamp of C++. It's worth knowing C++ well enough that you can hack systems code though. I wouldn't say "only learn C and not C++ for systems hacking!"
- thomasptacek 19y agoI reverse engineer and audit systems software for security flaws (OS kernels, hypervisors, filesystems, drivers, and higher-level stuff like client-server and message passing systems). I've looked at a lot of other people's systems code. Most of it is C, not C++. It's mostly C on Win32. It's mostly C on Solaris. It's mostly C running in VxWorks. Most systems code is C. Knowing both C++ and C, my counsel (worth what you paid for it) is that C++ is a waste of time for systems work. If you want to allocate a year of your life to minutiae, learn X86 runtime code generation; it'll help more with systems work, and you can write your own DSLs in C.
- dfranke 19y ago> learn X86 runtime code generation It's much easier just to embed LLVM.
- thomasptacek 19y agoThat counts. LLVM. Better than C++.
- jey 19y ago"It's mostly C" isn't an argument, it's an empirical observation. There are various historical and technical (ABI issues mostly) reasons to use C for kernels, hypervisors, filesystems and drivers. I'd still use C++ for all of the above, although a restricted subset if I'm writing a kernel, hypervisor, or driver. I would only export a C interface from my C++ code if it requires dynamic linking though (e.g., I would never write a export a kernel's API for device drivers in C++) I also don't mean learning minutiae for minutia's sake. Most of my work has been on compilers and servers, and I'd gladly take C++ for these tasks. Why should I do the extra footwork to write it in C? A sibling post mentioned LLVM. This is a great case in point. You should look at the GCC source sometime... it's absolutely atrocious. LLVM is on the entire opposite end of things, the code and design are beautiful. Hacking on GCC requires 80 pounds of body armor and a consultation with the local shaman. Hacking on LLVM is fun, exciting, and easy. "Reload is the GCC equivalent of Satan." http://gcc.gnu.org/wiki/reload http://gcc.gnu.org/wiki/reload GCC's internal garbage collector. Yes, they really wrote a garbage collector for a C app, and dealing with it is just as pleasant as you'd imagine. http://gcc.gnu.org/wiki/Memory_management http://gcc.gnu.org/wiki/Memory_management
- thomasptacek 19y agoThere's definitely good C++ code; the MIT PDOS Click router (http://www.read.cs.ucla.edu/click/ http://www.read.cs.ucla.edu/click/) is another great example. But there's good Perl too. I'd definitely use LLVM before I hacked up GCC.
- bootload 19y ago"... Sometimes you really do need to write systems software. In these instances, I'm still going to use C++ ..." So you write non-portable code? c is still the language of choice for "portable" system work because c compilers can target lots of different systems. You cannot say this for c++. Not because of language deficiencies but limitations with the toolchain. Wx faces the problem of using 10yo c++ features because of the lame nature of c++ compilers (Codingstyle Interview with wxWindows Developers, Steve Frampton, 2002) ~ http://codingstyle.com/index.php?name=News&file=article&sid=43&theme=Printer http://codingstyle.com/index.php?name=News&file=article&...
- kingkongrevenge 19y agoJust target g++, which covers all major platforms. C++ is portable. I can't believe all the pro C ranting. Do you people just enjoy typing? C++ is far more succinct. The same people agreeing with Linus here probably post elsewhere in favor of high level interpreted languages like Python over Java and C#.
- jey 19y agoThis is just an outdated understanding of C++, unless you really need to target a VAX or something. I don't intend my programs to run on machines more than 10 years old anyway. A decade ago, the non-portability of C++ was a real concern.