Live data from Hacker News

Why You Should Know C++

unknownprogrammer.com

31–40 of 63 posts

Re: Why You Should Know C++

#31
I'll go for a point-by-point critique.

Point 1 tacitly assumes that learning C++ not only teaches you a common subset of many other popular languages, but also is the easiest way to learn said subset. This is wrong: a lot of simpler languages can teach you the same, e.g. JavaScript or pre-1.5 Java.

Point 3 says a given code sample in the wild has higher probability of being in C++ than any other language. This clashes with my impressions.

Point 4 assumes that the main difficulty of C++ is due to pointers and manual memory management, and that knowing your way around those issues will help you in other programming areas anyway. This sounds wrong to me: C shares those "difficulties" with C++ and isn't generally regarded as a hard language. The difficulty of C++ mostly stems from design decisions unique to C++ and useless elsewhere, like template metaprogramming or the dangerous combination of manual memory management with exception handling.

Point 5 implies that C++ invented parametric polymorphism and that this facility is essential to make algorithms work on a variety of data types. Wrong on both counts: ML and Ada generics predate C++, and Smalltalk-like dynamically typed languages solve the same problem without type parameterization.

Point 6 assumes more libraries have C++ interfaces than C interfaces, which is wrong by an order of magnitude at least.

Point 9 assumes most programmers are more interested in performance-oriented and algorithmically complex projects. Can't give statistics here, but I'm a data point to the contrary: I love UI and frontend work.

Point 10 is valid.

My own reasons for knowing C++ are a combination of point 10 and the need to muck around with http://mapnik.org - the only C++ library I ever found useful. And its code sucks, I'd kill for a C/Python alternative.

Re: Why You Should Know C++

#32
post #7

Earlier quoted context omitted.

What's the point of using C when most modern programs on modern operating systems are written using frameworks that are a form of objectified C? All serious development frameworks nowadays for desktop applications are either C++ or Objective C. Most native libraries are one of the two. Even the driver SDKs are mostly build on an object oriented approach. And learning C++, you will know C. Your opinion is a popular op…

Windows API is pure C. GTK is pure C. And these are quite serious (and not exactly obscure) development frameworks.

Have you subclassed any GObjects lately? Or otherwise implemented custom GTK widgets? If so, you might know why GTKmm exists (nevermind that PyGTK, GTK# etc are arguably the intended ways to use GTK.) There is a good reason everyone in the Linux world screamed with glee when Nokia LGPLed Qt, and C++ (even the basic stuff) is a big part of that reason.

Re: Why You Should Know C++

#34
post #12

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... :-/

C99 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.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 sys…

The ML family of languages is my favorite (second only to C++, natch.) but their brand of parametric polymorphism is equivalent in C++ to MyTemplate (or, if you like boost, MyTemplate > would be more accurate.) They are not the same as MyTemplate. 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."

Re: Why You Should Know C++

#36
I agree with everything but (1), (5), and (10).

(1) Other languages may be influenced by C++ (especially at a syntactic level, and, superficially, in their object models). But those other languages are far easier to learn and become facile with than C++ is. Point (1) advocates for learning languages in the wrong order.

(5) Templates and generic programming are just tools to mitigate the badness of C++.

(10) Though a majority of the smartest hackers I've worked with know C, a minority of them are C++ developers. And that still leaves plenty of room for smart people who know neither language.

Re: Why You Should Know C++

#38

Wow, I like C++ (at least, more than most), but I don't agree on any of those points. In fact, I am sad to say that unless your job requires it, I can't really think of any reason to learn the language. It relies on a mixture of paradigms that are easier learned from other languages where they are isolated. And for lolevel stuff, you are better off learning C.

The points a useless. "Knowing C++ you will not be immediately seen as a hacker, but the inverse applies here." Learn it if you are curious, but don't learn it just to get a job.

Re: Why You Should Know C++

#39
post #32
post #7

Earlier quoted context omitted.

Windows API is pure C. GTK is pure C. And these are quite serious (and not exactly obscure) development frameworks.

Have you subclassed any GObjects lately? Or otherwise implemented custom GTK widgets? If so, you might know why GTKmm exists (nevermind that PyGTK, GTK# etc are arguably the intended ways to use GTK.) There is a good reason everyone in the Linux world screamed with glee when Nokia LGPLed Qt, and C++ (even the basic stuff) is a big part of that reason.

No qt is the reason. qt is well designed and thought, contrary to gtk. And it's not because qt was written in C++.

Re: Why You Should Know C++

#40
post #5
post #2

3. Code samples in books are more likely to be in Java or Python than C++. 6. Libraries are more likely to have native C bindings than native C++ bindings.

I agree, most of the points seem to apply more on C than on C++. Also this: 10. You will hardly be seen as a hacker if you don’t know C++ there are enough kernel hackers that are excellent C programmers, but don't know C++ that well. and this: 8. There will always (or, at least, for a very long time) be a niche for C++ There will also be a niche for COBOL programmers. That doesn't mean you should learn COBOL.

Just keep in mind that making a career out of maintaining other peoples' C++ legacy code is a highly optimized way to become the bitterest person in the world.
Post reply on HN