5 ms·
> C++ is just not a very good language. C is a fine language. This is the attitude that I really, truly do not get. If I want a linked list or any other commo
by TillE 16y ago
> C++ is just not a very good language. C is a fine language.
This is the attitude that I really, truly do not get.
If I want a linked list or any other common data structure in C++, I include the appropriate STL header and declare an object with the template syntax. It's two easy lines of code. If I want a data structure in C, I have to write it myself. From scratch. Every time.
C++ is a powerful high-level language. C is a low-level language where everything is explicit; I know this is "elegant" to many programmers, but really, I'm just trying to get things done, and C++ has served me far better in that practical role than C ever could.
I don't love C++; it has tons of flaws (many of which disappear if you use shared_ptr for everything). But I loathe the tedium of working in C.
- xpaulbettsx 16y ago> If I want a data structure in C, I have to write it myself. From scratch. Every time. http://library.gnome.org/devel/glib/2.28/ http://library.gnome.org/devel/glib/2.28/ makes C development much more pleasant. You could make the same argument against C++ if you didn't have STL.
- dasil003 16y agoWhen C was invented, half of all coding was systems programming. C does a great job of addressing that need, that's why it's a fine language. The fact that C is not great for GUI apps does not diminish C's quality for what it is, it's just not designed for that level of abstraction. C++ on the other hand, attempts to be designed for that level of abstraction, and so in fact you are better off writing most types of modern apps in C++ than C in absolute terms, but when compared against other languages designed for the same paradigm it falls down due to complexity overload. That doesn't mean you can't do great work in C++, but you have to really know what you're doing, which parts to avoid, etc. C++'s strength is being both fast and powerful, but most of the time you don't really need both those qualities. Game programming is a notable exception.
- wglb 16y agoThe "which parts to avoid" conundrum shows up as every outfit that uses it in any serious way has a different set of "which parts to avoid". It is just a mess.
- nostrademons 16y agoThe comparison isn't between straight-C vs. straight C++. It's between C with a good glue language (say, Python or Lua) vs. straight C++. If I want a linked list in Python, I do: frobs = ['foo', 'bar', 'baz']. The equivalent C++ is: vector<string> frobs; frobs.push_back("foo"); frobs.push_back("bar"); frobs.push_back("baz"); The reason people like these multi-language solutions is that Python or Lua is much, much more productive than C++ (as in, many times more productive), and yet the most programs have only a very small core that needs to run fast. You can write that small core in heavily-optimized C, making it quite a bit faster than kludged-together C++, and then write everything else in Python. And the total complexity of the system is still much less than if you'd just used C++ to start.
- rorrr 16y agoThis is not a linked list, it's a dynamic array. http://en.wikipedia.org/wiki/Linked_list#Linked_lists_vs._dynamic_arrays http://en.wikipedia.org/wiki/Linked_list#Linked_lists_vs._dy...
- tptacek 16y agoThat's a pedantic comment to make, given that Python doesn't care about the difference. Ruby calls the same thing an "Array".
- omnigoat 16y agoWell you've clearly never had to worry about memory paging and the cost of indirection, like I have (actually from memory I think you must have at some point?). The difference is real and significant. Try writing a particle system using a linked-list over a vector, the speed difference will be crippling. I really feel that most of the hatred for C++ stems from people not understanding why such complexity exists in the language.
- nostrademons 16y agoThe point is that you don't have to worry about the difference in Python, because you don't use Python for the parts where performance matters. If you've got a million instances in your collection, you probably want to write your data structure and key traversal functions in C. Python has a sequence protocol, so you can easily wrap it to operate on it just like a native list (which is really a vector), but the operations that need to be fast should be in heavily-optimized C. In every system I've written, there's been a large chunk of code that runs on startup, or implements a feature that only 1% of users care about, or performs setup for one of these expensive operations but itself only touches a few data items. This usually consumes about 90% of the code but only about 1% of the runtime. Heck, probably 50% of my code never makes it to production at all, because it's exploratory or analysis code that's intended to define the problem, not implement the solution. Why not write it in a language that makes you really productive, and spend the time saved to optimize the hell out of the remaining 10%?
- tptacek 16y agoSTL is great. I like STL so much that, after moving from my startup (where we did C++) to a friend's (where it was all C), I backported a void*-specialized version of STLport's <map> and <vector> libraries. It took a couple hours. The pain of C++ isn't worth the benefit of the STL; fortunately, you don't have to suffer C++ to get access to its better libraries. It is flat-out not true that you need to write data structures in C each time you use them. The programmers that do this are, in my limited experience, uniformly bad. I wouldn't even write a linked-list for fear of screwing up a corner case on deletion. There are libraries for everything, and they're plenty fast. They're just less pretty looking.
- cpeterso 16y agoAssuming you can use STL. Many projects can't use STL because of its reliance on C++ exceptions (cf. Mozilla or Google's C++ style guides). If your legacy code or some third-party library is not exception-safe, then you can't create reliable C++ software using the STL.