40 points · by w4rh4wk5 · 13y ago · 113 comments
1. You do any desktop programming. You will meet c++ along the line somewhere for certain, be it some win32 abstraction, Qt, Wx etc. I'm ignoring apple here for ref.
2. If you're writing high performance software (scientific computing, gaming, trading etc).
I can't really see many other use cases that can't be solved either via C or a high level language easily.
To be honest I really was indifferent about C++ for years but C++11 seems pretty good so far. I can see it creeping in places where JVM/CLR are being pushed a bit hard and in the systems programming space, but on the basis that some people like myself are still maintaining oooold c++ code, I can't see that being that soon.
That sounds like a red herring. Can C++ be easily compiled for heterogeneous architectures and distributed systems? Does it support massive concurrency in the Erlang/Go style? Is it easily and efficiently vectorizable the way that APL was once? Somehow I've always felt that C++ can do "anything" at the cost of "being equally bad at everything". Regarding C++11, I really like Rob Pike's comment on how the creators of C++ seem to think that the problem of pre-C++11-C++ was that "it apparently didn't have enough features".
Cats can be skinned in a multitude of different ways. No specific knife is required but some experienced knife-wielders are more important.
Rob Pike is pretty cool but has blinkers on as he's a captive research executive rather than someone with dirty hands on the ground in some enterprise outfit.
I think you're quite mistaken here. These languages solve concurrency at the language semantics level, and then, some of them implement the semantics in a VM, but the VM (in case of Erlang, no Go implementation in use has one) is a tangential issue. To say that these language "solve concurrency problem in the VM" simply doesn't make sense. Languages are languages, they are not implementations.
C++ is just a language in which you are free to build those abstractions into in any form you choose.
Well, there's Turing completeness, and then, there's actual usability. Consider transactional extensions, for example. Haskell gives you a type system for that. In Lisp, you could achieve the same using a code-walking macro library. C++ gives you...what, pattern-matching based template metaprogramming? Ugh! The "language" for that, while Turing-complete, isn't even identical to the one used for run-time code. I've seen a factorial written that way. I don't want to imagine how more complex code like that must look like in C++. Even D is better at that!
If that wasn't possible, then our SQL server installation (all c++) wouldn't quite happily run a single process on each of our 48-core nodes with 128Gb of RAM, nor would it cluster and replicate amongst all 8 of them and deliver 10,000 queries a second whilst yawning.
I didn't say it's impossible in C++. It's just that it's masochistic, that's all. You could easily argue along the same lines that COBOL is a well-designed language because millions of applications have been written in it that power the reliable day-to-day operation of banks you've invested your money into. Yes, they have been written, but at what human cost?
Rob Pike is pretty cool but has blinkers on as he's a captive research executive rather than someone with dirty hands on the ground in some enterprise outfit.
"Captive research executive?" What does that even mean? He certainly has more than enough of his share of dirty hand, while continuing doing so even today, and I won't even comment on that "enterprise outfit" nonsense.
"Finally, although the subject is not a pleasant one, I must mention PL/1, a programming language for which the defining documentation is of a frightening size and complexity. Using PL/1 must be like flying a plane with 7000 buttons, switches and handles to manipulate in the cockpit. I absolutely fail to see how we can keep our growing programs firmly within our intellectual grip when by its sheer baroqueness the programming language —our basic tool, mind you!— already escapes our intellectual control. And if I have to describe the influence PL/1 can have on its users, the closest metaphor that comes to my mind is that of a drug. I remember from a symposium on higher level programming language a lecture given in defense of PL/1 by a man who described himself as one of its devoted users. But within a one-hour lecture in praise of PL/1. he managed to ask for the addition of about fifty new “features”, little supposing that the main source of his problems could very well be that it contained already far too many “features”. The speaker displayed all the depressing symptoms of addiction, reduced as he was to the state of mental stagnation in which he could only ask for more, more, more... When FORTRAN has been called an infantile disorder, full PL/1, with its growth characteristics of a dangerous tumor, could turn out to be a fatal disease."
First of all, it's not my line, it's Rob Pike's line. Second, upon seeing how the C++ people intend to fix deficiencies of C++ by throwing even more features at it, it's very difficult to see it in any other way. Third, the only "anti-intellectualism" I see here is named C++: It's actually symptomatic of certain organizations that instead of trying to see the big picture and really fix things in a systematic way, they "anti-intellectually" hack and tweak and tinker and micro-optimize. For example, IBM has been doing that in the 1960s with their HW architectures before they got their shit mostly together, which is why the ACS project failed, only for it to be rediscovered forty years later, with modern CPUs finally (!) utilizing these ancient but very well working techniques, such as superscalar out-of-order design that will celebrate its fiftieth birthday in a few years. Now, the same breed of people who ditched ACS in the 1960s are apparently in charge of design of mainstream languages. I wonder if we'll survive the next decades in good mental health before enough people realize the same thing again, ditch that crap and start all over again.
Should you learn it? There's still a ton of software written in it and it has one of the best compiler ecosystems; for many applications it's one of the only practical options for a production system. Every programmer should know enough C++ to understand templates, RAII, operator overloading, things like that, if only to compare with approaches in other languages.
Should you build new systems in it? I would avoid it if possible, but once you learn the language, hey, maybe you'll love it. And if so, there's no shortage of C++ programmers to work with you.
“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” — C.A.R. Hoare, The 1980 ACM Turing Award Lecture
You can also learn more than one langage because they fits domain of excellencies you want to master:
- C low level programming (zmq switched from c++ to C because of error handling) - high level portable language that can bind on libraries (python to avoid hispter mac users using ruby) ; - something for concurrency (Go); - R-project for data treatment; - vanilla JS because mixing LISP difficulties with braces syntax is insanely cool; - PHP and Perl to feel with your guts what a wrong language is (hint: it is all about maintainability); - ASM 68000 because motorola 68000 is the most beautiful mix between a good design and implementation and it will make you truly able to build a consistent mental map of what a computer really is; - Tk because 25 years it still is the most portable way of doing GUI and has inspired everyone; - Forth because it is fun to use postscript as a real programming language; ....
And yes I have watched the code and found a bug. The clock used in python is mononotonic but may change its frequency and the the time structure is wrong on 64bits architecture there is a cast to signed long long where it should be unsigned long long.
So if I can find stuff easily and see bugs, it means to me the code is well architectured and readable.
http://250bpm.com/blog:4 http://250bpm.com/blog:8 - Why should I have written ZeroMQ in C, not C++
(i don't have a dog in this fight, just throwing fuel / data on the fire...)
The better the artchitecture is designed the funnier the assembly is. It makes you feel both miserable (you discover all the stuff we considered as granted as dynamic hash tables don't exists) and like the king of the world (yeh you made a led blink \o/).
I pecularly recommend it for people with bipolar personnalities, it will suits them 200% ;)
If you are going to learn it, learn it in full. Understanding most of http://yosefk.com/c++fqa/index.html ought to be a requirement to put "C++" as a separate item from "C" on your resume; people who put "C/C++" on their resume make me more likely to believe they only know C++ as a kind of super-set of C and they will likely program C++ code in a very Cish style, also they will likely make more mistakes caused by a faulty assumption that C++ does the same thing C does -- like a keyword means the same in C++ as it does in C.
A lot of places have sane requirements and restrictions on what you can do in your C++ programs there. e.g. http://google-styleguide.googlecode.com/svn/trunk/cppguide.x... But to understand the decisions you probably need to learn about the thing being discussed... And then learn why other programmers want the thing to be enforced or restricted so much. A lot of times it's just so even C++ programmers whose C++ knowledge is summarized as "C with classes!" can still be effective programmers.
I wouldn't suggest learning C++11 specifically. Learn C++98, then learn what new features C++11 has on top of that (there aren't that many).
Could "C/C++" on the resume also not mean they see C as a subset of C++, they program C++ code in C++ish style, but also feel comfortable with C? (I understand C is not a true subset anymore, but it seems close enough to allow me to do programming in C every once-in-a-while I need to.)
And afaik most game engines are written in C++ because of performance and memory management.
The game industry uses C++ because most of it is consistently about ten years behind the rest of the industry (remember how long it took them to switch from asm to C? and then from C to C++) -- the charitable viewpoint for this is that the industry is conservative; this is also a consequence of the toolset in the embedded world.
Any natively-compiled language with a good compiler will produce pretty fast code without too much work, but to get really fast code in any language, you really need to know what the compiler is doing and be able to tweak it from the language; writing really fast code in C++ requires about as much work and as much thought (but less knowledge of your target compiler and runtime) as writing really fast code in Common Lisp or Scheme.
It's important to note that it's actually easier to write slow code in C++ than in C if you're not careful; C++'s powerful abstractions cut both ways. Unless you explicitly forbid a number features, C++ takes away your ability to look at an isolated block of code and get an approximate "in-head" assembly of it.
All that said, if you want to work in the game industry, you need to learn C++, you have no choice. But at the same time, you could be experimenting with building games in newer languages like D, Rust, and maybe more exotic choices like SML using MLton or Gambit Scheme (maybe using Stalin for a final pass).
I hope this is helpful.
So why the heck are you asking the question ?
you already know the answer.
Oh yeah, let's put Chromium, Firefox, and all of KDE on that list too.
As a person who is proficient in both C and C++, I find this constant war ridiculous. Neither languages are obsolete ok? Which one is best for you depends on the circumstances. Stop speaking in absolutes.
As for C it is a great language but it is pretty much only for either old stuff or system level stuff. In the real world I see people pick C++ over C if possible.
Maybe so, but the programmers I know who have switched from C++ to Haskell/OCaml/F# never seem to regret it. They are getting more done in less time, and spending a greater fraction of their time writing good software than tracking down annoying low-level bugs. The small trade-off in performance does not seem to be an issue, and in the few places where it is, some C or assembly code invoked via an FFI solves the problem.
"C++ is still one of the most flexible languages for application development"
Only if you are not counting the overhead of actually getting a complex C++ application to work reliably. Even the new abstractions in C++11 and C++14 seem to force programmers to deal with low-level issues than in almost every case are a distraction from the high-level problem being solved.
All languages make tradeoffs. You need to understand your domain and the tradeoffs associated with them.
If you're doing any embedded programming you're going to be using C. C++ is pretty much exclusively used in the gaming industry, and there mostly because of historical reasons more than anything else (all the popular frameworks are written in C++).
I'm curious how you've come to that conclusion? C++ is used in most of the major web browsers, most of the major database engines, most of the major office program suites, it's widely used at Adobe, Microsoft and Google... C++ is in the top 5 of most language popularity rankings (TIOBE, langpop).
Sure, C++ has its issues, but claiming it's only used in one industry is way off base.
The answer to that question, IMHO, is yes which is what the OP wanted to know. Had they asked what languages they should learn I would put other languages above C++ but that wasn't their question :)
It's likely that your idea of what is 'inherent' to C++ is just wrong. First of all, C++ is almost a superset of common C so, yes, it can can really replace C entirely and completely. Whatever grievances you have with the language don't change the reality that even embedded code benefits from, and has been gaining ground in, C++ for quite some time.
In any case, I'm not arguing C++ is inherently 'better' than C. I'm just saying betterunix's assertion that C++ is somehow 'legacy', and C somehow isn't, is weird and illogical.
Now only you will truly know if C++ is suitable for the tasks you do but unless you work at a university then chances are C++ will be good to great for whatever you need.
With this said, that's just me and the way the world has worked for me. There are tons of applications were C++ is the right answer and C could never fill the bill. If you just want to learn native and low level programming, learn C instead. Its simpler, easier to learn and has more use cases(Linux kernel, some OS-less micro-controllers)
So to answer your question, "ehhh... sure. maybe?"
I would learn C++ if you need to know it to get your job done.
Like others have said, C++ is a complex language. Some people don't like it as a "language", some people like all the features it has. But at the end of the day, it is complex to learn and understand.
Also you have to think about a lot when programming in C++. You have to think about objects in terms of their life cycle. Compared to a garbage collected language, this accounts for mental overhead that could be applied elsewhere.
A couple of other negatives about C++:
1) Its harder to interface than C.
2) It has many different flavors that vary depending on what platform you are on.
3) Up until C++11 it didn't have built-in regex.
A couple of positive things about C++ and learning C++:
1) The STL is great, and has patterns that you can apply to other languages.
2) Generic programming to write re-usable code in C++ can be quite fun, and you can learn how the compiler can help you during compile time (+).
3) Learning OOP in C++ can be an artform, and can be fun. There is a lot of bad C++ out there, but there is some very elegant C++ out there as well.
4) You will learn that C++ is not C. You will also learn to chuckle at anyone that writes "C/C++". (Hint, if they write this, then they do not know C++)
(+) Note on this point: Some people from the more dynamic languages might poo poo this as not needed, and that in their favorite language you don't need to define types. This is a mixed bag, on one side, that is true and can let good programmers work faster. However, they either have to not test, or perform all tests at run-time. A compiler and linker can tell you much faster if you have done something stupid like call a method that doesn't exist. In a dynamic language, you have to write tests and hope you happened to test that branch of code where you made the mistake.
Assembly and C map very closely to actual hardware, but don't have a very high abstraction capability.
Haskell, Erlang, Python, LISP, etc. have abstractions up the wazoo, but there's big box labelled "magic" between what you write, and what gets run. That's because it's easy to construct systems which have nice theoretical properties, but are completely incongruent with shipping chips, requiring a black box in the middle that is doing who-knows-what kinds of translations, continuously.
Intel will never ship a CPU which natively executes functional code, for example, because fundamentally computation is an imperative process. You have information (entropy) and you want to turn it into a useful result; that involves moving bits, comparing them, performing simple computations on them, and iterating. That's what chips do, and that's what C++ does too--the fundamentals--but with more abstractive power than C when it is needed.
If you think that being both "in tune" with the hardware and achieving high abstraction in a single language is difficult, you're right--and C++ is difficult to learn and use. There is no free lunch there. But the results speak for themselves. Almost every single piece of software I use on a daily basis is written in C++.
You might consider learning C{,++} if:
If you need to interface with hardware at a very low level, such as when you are programming a microcontroller or writing a device driver.
You have a reasonably small application and you need the best performance possible. Don't use them because "C++ is fast". C++ is fairly fast by default, but so are many other languages where it's harder to shoot your foot off. Use C or C++ because of the greater scope for optimization in memory layout and other sorts of painstaking optimizations.
Learn it because you want to create a library that can be used by many other different languages. Pretty much any language has some method of calling a C function, it's pretty simple. Making calls between languages that have their own garbage collectors is more complicated.
Learn it to teach yourself about how your computer works. you could also use assembly language here, but C works well enough. Getting a sense for how other languages work under the covers can help you understand performance trade offs in other languages better.
give some context.
"Is C++ still worth learning for this or that kind of job or field?" is the question you should have asked.
Now i would say most programming languages are still built on either C or C++, and a lot of them allow C or C++ extensions,even hipster's nodejs. You cant be an expert on these solutions/languages without knowing the lower level.
"...abstraction mechanisms that allows programmers to express ideas beyond what I can imagine with no overhead compared to hand-crafted code."
This is superficially similar to the Lisp community's "sufficiently advanced compiler," but in C++ it really means that high-level features are thoroughly undermined by low-level concerns (as opposed to just being slow until better compilers come along). Other languages seem to get high-level abstractions right, in the sense of exchanging a constant-factor loss in performance for a large gain in programmer productivity.
Also, why limit ourselves to "mainstream" languages? Once upon a time C++ was not mainstream. Why should we shy away from Lisp, OCaml, or Haskell just because they are not popular? In every discussion about C++ and its technical ups and downs, someone points to its popularity, as if that were some kind of justification. The history of computers is overrun with examples of popular-but-inferior technology.
I would say that it's a good thing to at least keep an eye on and have some understanding of. If not for anything useful then you can at least experiment with http://libcinder.org/. I do also find reading the c++ standards committee articles a worthwhile activity just to further my understanding of how things like lambda expressions can be implemented and their impact on other concepts.
I enjoy C++, and learned as the language right after Visual Basic 6 at around 2008.
You can easily imagine how things "could" be implemented on top of C in C++.
The most difficult thing about C++ is passing over all the negativity hyped by the "other" camps, and then learning from the right people (who will tell you what things have gone wrong and have their own philosophies of using the language). The new standards of the language feel like they're more scripting than erecting object oriented cathedrals. I enjoy reading topcoder submisssions and editorials on their SRM problems. I believe it can give a perspective on how C++ can be used in a terse and narrow domain.
TL;DR: At any place where C makes sense, C++ has a lot to be offered to be ignored. Try to consider the source when checking criticism. Find legitimate examples of C++ from OSS and topcoder SRM submissions.
If you're not, then IMO, C++ is not worth learning. In the words of Alan Perlis: "A language that doesn't affect the way you think about programming, is not worth knowing" The main contributions of C++ is implementing abstractions well known in other languages - OO, generic programming - in a C-like syntax. C++ is not the best language to learn to understand these concepts - there is too much low level complexity to deal with.
But if you're looking for language with the performance of C and with available high level abstractions, C++ is still the best choice today.
C++ is one of the few (maybe the only) languages that gives you enough high-level features to be productive, but doesn't do so at the expensive of ruthless runtime efficiency. If you need to squeeze every ounce of juice out of a machine, but still require the ability to create good abstractions, C++ is for you.
-C++ is very large language and the standards committee works hard to make it larger every day. Every organization makes use of a subset of C++ but likely a different subset. C and Java are much smaller languages.
As John Carmack says "Any abstraction that compiler will accept will eventually make it into a sufficiently large codebase"
-Familiarity with an organization/codebase specific subset of C++ is necessary for a number of significant career paths in software development. Chromium and related technologies, Google's core infrastructure, Java runtime engines, game engine developement etc.
I fundamentally don't think you should try to "Learn C++". If you are interested in career path the has C++ as a prerequisite. Learn the C++ style of a similar OSS project.
The answer is "it depends" (of course!). If you plan to hack into some kernel source code, device drivers, legacy software, or high performance softwares, probably it's worthy.
My advice is: once you learned one language for each type (functional, procedural, object oriented) and a scripting language (python, perl, ruby, ...), then get a project and learn while hacking.
Exactly. Still yeah, I agree with you (and Linus Torvalds) on the fact C should be used.
Calling the language you write OS X drivers in C++ is also a stretch: https://developer.apple.com/library/mac/documentation/portin...
Only someone who never used templates or did template metaprogramming would state such a thing ;). C and Java -> C++ is not just a matter of syntax.
1) I currently do Obj-C (apps) and Perl (scripting & tools)
However, for a quick & dirty answer: no, go with C (much more universal).
On another note, if you wonder if you should do, seems like you don't have a reason to... Why are you doing it?
In general, I'd say no. The niche it fills (high-level features bolted on to a low-level language) is not that useful and it doesn't fill it well.
C, on the other hand, is worth learning.