4 ms·
The STL is actually pretty lean compared to the standard libraries that ship with most popular programming languages these days and if you leave the iostream st
by cageface 12y ago
The STL is actually pretty lean compared to the standard libraries that ship with most popular programming languages these days and if you leave the iostream stuff out it's fast and doesn't take up much space in the binary. I've used it with great results on iOS devices. My first step in creating any new class is subclassing a no-copy parent, which in my experience eliminates most of the nasty gotchas with accidental copies. I have yet to get any RAII weirdness.
I've considered reverting to plain C to make it easier to interface with other languages like pure ObjC and now Swift but when I think about how much extra work this is going to entail for absolutely zero benefit to my users I always give up the idea.
- sillysaurus3 12y agoMy first step in creating any new class is subclassing a no-copy parent That's exactly why, when presented with a choice between C or C++, I'll choose C every time. First, because it's often inexperience with other paradigms that forces programmers into an "everything must be an object" mindset. Second, because the fact that you need to learn a gargantuan amount of trivia to use C++ inheritance non-dangerously is a sign of underlying derangement. Third, because through experience I've learned that C is far less scary once you embrace standard patterns for accomplishing various tasks. The total linecount isn't significantly increased by using C over C++. The codebase complexity isn't increased. What I like about C is that it gives you a set of inalienable commandments: thou shalt not go completely nuts with {inheritance, template metaprogramming, flavor du jour}, because you can't. In the hands of an experienced programmer, C gives you more reliability than C++ precisely because there are fewer gotchas. The dangers are straightforward: free memory after you use it; have a single place that a pointer is "owned"; check your lengths before copying between buffers.
- cageface 12y agoI actually very rarely create class hierarchies in C++. I do, however, define and implement interfaces and this is a simple, no-brainer technique that eliminates a whole class of gotchas when I do it. The total linecount isn't significantly increased by using C over C++. The codebase complexity isn't increased. This I can't agree with at all. If I had to rewrite my current codebase in C it would be substantially larger and buggier and much less flexible. I know because I've tried this experiment already. This is even more the case with the C++11 syntax enhancements, which reduce the verbosity of C++ a lot. My only real complaint with C++ is that it lacks a proper ABI so I have to wrap it in C if I want to use it from another language. This wasn't a big deal when I could rely on Obj-C++ but Apple's new Swift language has thrown a bit of a wrench in this scheme.
- sillysaurus3 12y agoThis is even more the case with the C++11 syntax enhancements, which reduce the verbosity of C++ a lot. Maybe true. I bailed from the C++ world before C++11 became pervasive. But if you use C++11 you risk leaving VS2010 users (and below) in a situation where they can't use your code at all: http://blogs.msdn.com/b/vcblog/archive/2010/04/06/c-0x-core-language-features-in-vc10-the-table.aspx http://blogs.msdn.com/b/vcblog/archive/2010/04/06/c-0x-core-... And C++14? No idea what version of VS supports it. But using C++14 will definitely mess with people who have older compilers. And those people don't always have the luxury of just buying the latest version of VS. Who cares about Windows? Well, anyone who's into the open source movement should be sympathetic to people who are forced to use a certain operating system but still want to get into programming. The spark for people's desire to become programmers often starts by wanting to customize their environment. That leads them to shell scripting, which is a stepping off point into more advanced programming. The main point is simply that the C++ ecosystem has so many "gotchas" and timesinks that when forced to choose between C++ and C, an experienced programmer will save time with C, mainly because their years-old patterns will work regardless of what environment they're in. There are still some gotchas, of course; you can't use unix signals and expect them to be cross-platform. But it's far more straightforward than trying to get your codebase compiling on five different compilers. Of course, choosing Python or some higher level language is almost always the best cost/benefit tradeoff.
- cageface 12y agoC++ standards compliance is better now than its ever been. You can't have a nice modern language and expect to support a four-year old IDE too. C++14 is mostly a minor refinement of C++11. You get a much nicer language already in C++11 that you can use pretty freely on modern platforms. Sure, use the highest level language you can afford to use. But I can't agree that experienced programmers will in general choose C or be more productive in it. The counter-examples are almost too numerous to even know where to begin. Surely the people behind Photoshop, Chrome, Renderman and Cubase etc. are aware of C and made a conscious decision not to use it.
- 12y ago
- mtdewcmu 12y agoLinus Torvalds has written quite eloquently in defense of using exclusively C in the kernel, pointing out some brilliant insights. Of course, the kernel is his at the end of the day, so he doesn't really have to be persuasive and there's a lot of colorful language mixed in to those forum posts, too, which turns a lot of people off and prevents them from hearing the brilliance. But you could hardly pick a harder and more mission-critical project than the kernel, and the result speaks for itself. Most projects are not the kernel, and for most normal-size projects, you'll probably get better results by picking a language you are experienced with and familiar with, rather than one that's in some sense universally optimal, but you have little experience in. But to sum up the advantage of C: C is for when you don't want any surprises. It's a very un-surprising language.
- sillysaurus3 12y agoThat's very interesting! Would you link to some of Linus's writings? Alternatively, I could try to search for them myself if you point out some keywords to google for. Did you have any particular articles in mind?
- mtdewcmu 12y agoSure. Here's one I bookmarked a long time ago: http://www.realworldtech.com/forum/?threadid=104299&curpostid=104196 http://www.realworldtech.com/forum/?threadid=104299&curposti...
- ahomescu1 12y ago> But to sum up the advantage of C: C is for when you don't want any surprises. It's a very un-surprising language. Actually, judging by the quantity of unspecified/undefined/implementation-defined behaviors in the C spec, I'd say C is full of surprises.
- mtdewcmu 12y agoI've seen lists of those, and they are pretty esoteric. I don't think I've ever stepped on one accidentally.