Ask HN: C vs C++
As a fledgling programmer, I need some advice. I made a list of languages to learn by next year and on the top of the list is C/C++ (figured that's a good place to start). However, a buddy of mine, an experienced programmer, suggested I drop C++ and just move on to JAVA after C. When asked why, he said 'C++ is way too complicated and error-ridden to serve any real purpose. C is more than enough'
Is this true? Should I forget C++ and move on to another language after C?
22 comments
[ 3.1 ms ] story [ 52.2 ms ] threadIf you want to build new system with Linux/BSDs. Then learning C is enough for you to do all useful things. Then you learn Java just as your friend says.
C++ is really complicated if you use features beyond basic templates and classes. And in reality, it lacks of standard Application Binary Interface for using binary libraries as C does. And different compilers may interpreter some spec in C++ differently.
C and Java is much simpler and uniform.
Do you want to learn those languages for your career or just for yourself ?
At the risk of being grumpy, I'd make a longer reply, but I already blogged on this just this morning.
http://www.whattofix.com/blog/archives/2009/05/tired-of-erla...
So go with C++. It doesn't have as many letters as Java.
I like pontificating as much as the next guy. But there's this pattern that keeps repeating: person asks question. People speculate on what they might have meant and offer answers. Person comes on and says no, that's not it at all. Then people spin off on that piece of information and speculated on what the situation is. Repeat and rinse.
Should I study C++ or Java? Well gee, what's important to you? Picking up complex concepts? Learning to work in large shops? Becoming an all-round nerd? Without context -- and a lot of it, including your life situation and priorities -- it's just an invitation to bullshit. Even then there's plenty of room for disagreement. It's like asking, What kind of music should I learn to like?
Why do you need to move on to anything else? As your friend said... "C is more than enough".
I prefer to focus on lists, graphs, queues, objects, events, continuations/control-semantics, and communication messages. I prefer to code in a high-level languages that allows me to get lower and lower as my needs for performance arise, and C is not it; in C I would need to build up my language to the higher semantic level my applications usually require, before I can even see it work. It puts the performance cart before the usefulness horse.
Anyway whichever way you go know that idiomatic C and C++ are very different(see http://www.research.att.com/~bs/new_learning.pdf for an idea of the differences). If while learning C++ you notice that it looks like C know that your source of info is doing it wrong. In fact I find idiomatic C++ to be much less error prone than idiomatic Java.
however, your best course of action depends on what you're trying to accomplish. he may have produced a good suggestion despite the reasoning being flawed or based on bad information.
I would say learn both, once you learn one it's not far off the learn the other. Knowing straight C ways including manual memory management, and learning C++ along with STL/Boost is a powerful combination.
C has a huge number of libraries already out there to do everything and anything. C++ has STL/boost which makes life very easy by giving your a lot of high level algorithms at your fingertips. Now wrap your C libraries in classes and use them in mix with STL/Boost. Now that's a powerful combination, best of both worlds.
In short: learn C++ if you expect to program in C++, but prepare to spend a lot of time before you get the good "I'm sitting on top of a seven-wheel motorcycle at 200mph, wheeee!" feeling C++ can give you.
C++ is a big, clunky, difficult, ugly language. Understanding C++ is an accomplishment, but not because it involves any fundamental learning beyond the peculiarities of that language. As a programmer and computer scientist, C++ will teach you how to design a clunky mess of a programming language. But it is widely used, for good reasons. It's the right blend of performance and abstraction for many applications. It's a good language--maybe the best--for learning certain data structures, just because it combines pointers (data structures are mostly built out of pointers) with encapsulation (which helps reinforce the mental model that, for instance, rotation subroutines are part of what makes an AVL tree an AVL tree). And as an application language, it's very much usable. So it is worthwhile, but probably not a high a priority as C (or, indeed, other languages that can teach you more than simply how to use that particular language).
The bottom line is that they are both rather ugly but practical languages. C++ offers more abstraction means, but is more complex. But for larger projects, I'd rather have that then GLib style hacked up C.
If you want a well paid job in business area, then C# and/or Java.
If you want to broaden your CS knowledge, then Lisp, Smalltalk, Eiffel.
If you want to work on shrink-wrap software then C++.
It's worth pointing out that Bjarne Stroustrup, creator of C++, is critical of it.