6 ms·
I do, and I'm not a masochist. I use it to write small games on my own time. I used to loathe C++, but the C++11/14 dialect makes things much more pleasant. Th
by dmpk2k 12y ago
I do, and I'm not a masochist. I use it to write small games on my own time.
I used to loathe C++, but the C++11/14 dialect makes things much more pleasant. There's still a lot of details you need to worry about, but crucially these are details that other languages rarely give you a choice about. The only real alternative was C, but I'm tired of reinventing wheels and C++ has the STL. C also doesn't have the same support for value types which C++ does, and value types are really nice to use.
- harry8 12y agoValue types, as opposed to polymorphic types, ie pointers (including references)? struct IntForFoo { int value; }; when you use it you write a function that takes an IntForFoo as one of its arguments and you get type safety over other ints. Gently snarl at anyone who does a .value outside such a function. Include a constructor function, an assignment function... Remember that that typedefs just lie to you about the type, they don't change it for type checking... If you need to generate code, do it, macros and templates are just really crappy ways of generating code; you can do a lot better when you need to. But how often do you really need to and how often are you worshipping at the false idol of "must be general so can be used for 100 years" when that's really not the purpose of the code? Polymorphism and templates are overrated by C++ designers you don't actually need them and they encourage some awful designs.
- dmpk2k 12y agoOne of the problems with structs in C, is that you must explicitly call the destructor function if you have non-memory resources. In C++, a scope's closing } always takes care of that for you. As for the generated code bit, I assume you're referring to the STL. Writing my own data structures is explicitly what I don't want to do anymore. STL has it? Great, I use it and move on.
- harry8 12y agoSure use it if you understand it, ie vector where you reserve the memory up front to avoid future allocations and pointer/iterator invalidations or you don't care in which case use a friendlier or more powerful language maybe? Writing datastructures is much of what programming is, I know that's not what you meant and you use the basics of STL to build the real datastructure you want, but you care about performance and with STL it's not targeted at your case so when you get beyond prototype you have to rip it out anyway. Automatic destructor calls on leaving scope is the nicest part of c++ - shame it interacts with exceptions so nastily that nobody understands how it works. "Exception safe code" yeah, right, not in c++. Generated code - you can use macros, you can use templates. Or you can use anything that generates text and does what you want, more nicely than that.
- maxlybbert 12y ago> Sure use it if you understand it, ie vector where you reserve the memory up front to avoid future allocations and pointer/iterator invalidations or you don't care in which case use a friendlier or more powerful language maybe? std::vector implements one of the simplest data structures in computer science. If somebody doesn't understand the difference between, say, an array (however you want to call it) and a linked list, I don't want them on my team. > Writing datastructures is much of what programming is, I know that's not what you meant and you use the basics of STL to build the real datastructure you want, but you care about performance and with STL it's not targeted at your case so when you get beyond prototype you have to rip it out anyway. What are you talking about? More than a decade ago, there was a lot of interest in what kind of penalty there was in using C++ compared to C. There were several benchmarks run and papers written, including one from Alexander Stepanov (main contributor to the STL) that became an appendix to the standard ( http://std.dkuug.dk/JTC1/SC22/WG21/docs/PDTR18015.pdf http://std.dkuug.dk/JTC1/SC22/WG21/docs/PDTR18015.pdf ). The conclusion from the various experiments was that C++ performance was on par with C, and C++ often provided opportunities to optimize more than C did (e.g., passing a pointer to a function in C to the more common C++ practice of passing a functor with an inlineable operator()). The STL relies on those features that allow for a very efficient implementation. In fact, the main complaint I've seen is that the STL struck the wrong balance of preferring efficiency over generality ( http://www.open-std.org/JTC1/SC22/wg21/docs/papers/2007/n2271.html http://www.open-std.org/JTC1/SC22/wg21/docs/papers/2007/n227... , http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1850.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n185... ). > Automatic destructor calls on leaving scope is the nicest part of c++ - shame it interacts with exceptions so nastily that nobody understands how it works. "Exception safe code" yeah, right, not in c++. A decade ago, there was a period of maybe six months where people thought it might be impossible to write exception safe code in C++. It was solved, and the solution was to use destructors. You may have heard of RAII ( http://stroustrup.com/except.pdf http://stroustrup.com/except.pdf ). Alexandrescu even made it incredibly simple to do ( http://www.drdobbs.com/cpp/generic-change-the-way-you-write-excepti/184403758 http://www.drdobbs.com/cpp/generic-change-the-way-you-write-... ). > Generated code - you can use macros, you can use templates. Or you can use anything that generates text and does what you want, more nicely than that. So I have a choice between using templates, which provide syntax checking and type checking, or generating text in an ad-hoc way? And you actually recommend monkeying with text generation? For what it's worth, I do like C. But when I work in C, I need to rely on something like Apache's APR or GNU's glib to provide me with useful data structures. While those have been ported to all architectures I care about, there's something to be said for having data structures in the core library. I like C11. I like using _Generic in macros. I like variable argument macros. But if I'm working on a project where I need variable argument macros, I'm much more likely to pick C++ than to try to convince myself that I'm generating correct source code through macros.
- peterashford 12y agoAlright, to be fair I haven't coded in C++ for ~10 years so maybe I might just be a little smidgeon behind the times =)