4 ms·
I like to use C++ just as a better C. Things like single line // comments and not having to declare all your variables at the top of your functions is really u
by dhotson 17y ago
I like to use C++ just as a better C.
Things like single line // comments and not having to declare all your variables at the top of your functions is really useful.
STL is also really useful in that you don't have to (badly) reinvent basic data structures like vectors and maps. Of course, STL also means reading compiler errors that are pages long... :-/
- Dobbs 17y agoNot only are comment styles a horrible reason to pick one language over another, but you need to get a new C compiler. // is part of c99 and can be used without any special work in modern gcc. Also on the data structures. Base C does not include them but there are libraries for such data structures if you want such as glib.
- mannicken 17y agoSTL is way out of the realm of "just better C". It's pretty much several new concepts: object-oriented programming and aspect-oriented programming.
- silentbicycle 17y agoUnfortunately, this also means that working with any real C++ code base will involve working with code written by people most familiar with a different 20% of the language than you. I find my time is much better spent writing in a more flexible language that integrates well with C (I like Lua), and saving C for the small parts that actually need it. Also: I can think of few language that have worse object systems than C++. It's not exactly a shining example of OO done right. Often, an efficiency issue is better remedied by a fundamentally different design, rather than just "pushing harder", and C++ makes it particularly easy to lose sight of this.
- silentbicycle 17y agoC99 has single line // comments. It also has the restrict tag. About the idea of C++ as a better C, See "C++ - The Forgotten Trojan Horse". (http://ejohnson.blogs.com/software/2004/11/i_find_c_intere.html http://ejohnson.blogs.com/software/2004/11/i_find_c_intere.h...) If you're using C++ for the STL, keep in mind that the ML languages (OCaml, SML) also have compile-time parametric data structures, and they infer and check their usage for you. They also have a proper module system, so when you change a private variable, you don't have to choose between linking errors or recompiling damn near every piece of C++ code in your source tree. They're also pretty fast.
- chancho 17y agoThe ML family of languages is my favorite (second only to C++, natch.) but their brand of parametric polymorphism is equivalent in C++ to MyTemplate<T*> (or, if you like boost, MyTemplate<reference_wrapper<T> > would be more accurate.) They are not the same as MyTemplate<T>. This is by choice of ML language implementors, as they see it as a defect of C++ that every template instantiation has to be compiled independently. Instead, they turn static compile-time polymorphism into run-time dynamism using indirection and function pointers. (Maybe MLton doesn't do this, but I know GHC does.) It's the difference between C's qsort and C++'s std::sort. The latter blows the former out of the water when sorting small things. This brand of polymorphism is unique to C++ and until someone does it better (which no one seems to have any interest in, except maybe Walter Bright) then C++ will always be "the best C."
- silentbicycle 17y agoThis is why I said "pretty fast", not necessarily faster than C++. Using ML means trading a small percentage of C++'s raw speed for code that can be debugged, adapted, etc. with much less trouble. I have found this to be a more than reasonable trade-off in virtually all cases.
- deleted 17y ago[deleted]