6 ms·
Why You Should Know C++
- mooism2 17y ago3. 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.
- pieter 17y agoI 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.
- silentbicycle 17y agoJust 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.
- deleted 17y ago[deleted]
- kristiandupont 17y agoWow, 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.
- markessien 17y agoWhat'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 opinion among web developers and people who do not do desktop development, but in the real world, it has a lot more advantages to learn C++ instead of C.
- DrJokepu 17y agoWindows API is pure C. GTK is pure C. And these are quite serious (and not exactly obscure) development frameworks.
- markessien 17y agoThe Windows API is an array of functions that can be called the same from C as from C++. Microsoft provides several object oriented wrappers for this API, and it's very rare that any significantly large application is not calling the API over some kind of wrapper.
- DrJokepu 17y agoNo, I think it's C. It's written in C and was (at least initially) designed to be called from C code. I think #ifdef __cplusplus followed by extern "C" doesn't make a C API C/C++. Also the fact that there are several Microsoft and third-party wrappers out there doesn't make it any less C, at least in my opinion.
- markessien 17y agoI did not say it's C++. It's C, but it's rare that it's used directly as C.
- wheels 17y agoAnd, uh ... POSIX. The weapon of choice for UNIX black-belts.
- greyman 17y agoIf you take those points one by one, none of them is a reason to switch to C++. But for some kind of larger projects where efficiency is important, C++ is still one of the best choices. I went from C++ to C# and wouldn't want to go back, but C++ is still a strong and lively language with many active projects and a good future. If I would be forced to implement something outside the .net framework, I would not hesitate to pick it up again.
- wheels 17y agoI'd phrase the C / C++ rift a little more carefully -- To do low-level C++ you'll have to learn low-level C anyway and learning C in and out is a far easier endeavor than learning C++ in and out. So if you're wanting to dip into low-level stuff, you need to learn at least C and may want to learn C++ as well. (More generally the above does not hold -- the way you approach and solve problems in C and C++ does vary a good deal in higher-level stuff, but if you're doing bit-wrangling, you do tend to end up with something that approximates C bunched into classes.)
- datums 17y agoThe 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.
- deleted 17y ago[deleted]
- kwamenum86 17y agoIn the context of code sampled, the difference between Java and C++ (and PHP and Javascript and a few others) is trivial and will hardly affect your understanding of the code. These are all part of a family of languages with C-style syntax.
- dhotson 17y agoI 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.
- screwperman 17y agoI feel the most compelling reason to use C++ is that it is one of the de facto programming languages in competitions.
- silentbicycle 17y agoThis is the same reason I drive a NASCAR stock car to work. Seriously, the defining aspect of most programming competitions is that you're making a program as fast as possible, whatever it takes. C++ rewards this: if you keep sinking an order of magnitude more effort into it, you can seemingly always shave off another tenth of a percent of the time. There are some cases in which this is actually relevant (many involving graphic rendering, a niche I work in, PS), but they're really a tiny part of programming. It makes sense to code them in C++ (or C), but it's really not the best fit for more general development, which usually places a higher priority on being able to deliver an adaptable and correct solution.
- joezydeco 17y agoNo discussion of C++ should go without mentioning the C++ FQA (Frequently Questioned Answers). It carefully explains every single thing wrong with the language, and there's a LOT to explain. http://yosefk.com/c++fqa/ http://yosefk.com/c++fqa/ Skip to http://yosefk.com/c++fqa/defective.html http://yosefk.com/c++fqa/defective.html for a great overview. And if anyone ever mentions "templates" again I'm gonna smack them hard.
- sprachspiel 17y agoMy reason not to learn C++: There are so many things one should know, that it is not rational to learn all the arcane details of C++. Every decision to learn something is an implicit decision not learn everything else.
- tptacek 17y agoIf you know any other object-oriented language, it's easy to make the case that you should learn C and skip C++.
- plinkplonk 17y ago"You will hardly be seen as a hacker if you don’t know C++" Yeah right! You are "seen as a hacker" if you write code that is useful to others and/or is brilliant in some respect. Nothing to do with knowing a particular language. If knowledge of a specific language is a criterion, I'd rather have someone be an expert in C/lisp/smalltalk/haskell/prolog.... C++ originates or embodies no concepts that weren't discovered or done better elsewhere. e.g: An expert smalltalker is more likely to understand OO than a C++ programmer.
- cousin_it 17y agoI'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 http://mapnik.org - the only C++ library I ever found useful. And its code sucks, I'd kill for a C/Python alternative.
- utx00 17y agoreally? with python/ruby/clojure/erlang/lua/js coming up in the world? ... i thought this was going to be a 1991 article.
- tocomment 17y agoLife is too short for c++. That's what I always say (even at job interviews..)
- dryicerx 17y agoThere are indeed so many things to learn, but as a developer or someone who would be in the development world (be it building tech startups, developing software, etc) there is a must-know set of tools. C/C++ happens to be very high on the list. And learning more really doesn't hurt. Not just C++, but also learn C, Java, Perl, Python, Erlang, Lisp, PHP, Shell Scripting, Assembly, Ruby, along with their most used libraries/frameworks. The more diversify your skillets, the better you can use the right tool for the moment, improving performance of that, lower development time. (Eg. A spoon can be used to build a house, but it's hardly the best tool out there). This way, want to hack up a quick content management or low computational front end system, whip out your php/python/ruby with your favourite framework out. Got a bottleneck at high cpu or memory bound place, rewrite that piece in C/C++. Need to deploy a cross platform app really quickly, Java. Want to bind or write a test for a bunch of tools, use Python or Perl. The list goes on. Summary: Learn More, use the right tool, do less, get more accomplished.
- DougBTX 17y ago"C/C++" is not a single language, by all means learn C.
- deleted 17y ago[deleted]
- dryicerx 17y agoOne should learn both. If you spend the time to learn C, might as well spend a tiny bit more and learn the C++ concepts as well. There are ton of pure C libraries, but a lot of algorithmic stuff in C++ STL/Boost kinds, knowing both C and C++ is essential, each by them selves wouldn't necessarily help one too much.
- tptacek 17y agoI 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.
- deleted 17y ago[deleted]
- jcromartie 17y ago> your reputation as a programmer will be lower if you don’t know it I could learn C++, or I could learn Smalltalk, Scheme and Haskell in the same time and mental space.
- bigsassy 17y agoWhen I first started programming, people would say the same kind of things for learning some form of assembly. 10 years from now people will probably be making an article like this for Java and C#.
- sectorzero 17y agoIf you want to be a master of the machine use C/C++; if you want to be a slave use Java; If you want to be a slave of a slave then its C# for you. Simple :) ( Disclaimer : My comments are limited to only the above 'popular' languages in discussion. Also I program purely on *nix, so I am not aware of your other dark or better worlds out there )
- swolchok 17y agoDidn't we do this discussion already when the last C++ article was posted?
- known 17y agoWall Street runs on C++.