A friend of mine decided to learn some lower level language (to increaze his abilities) so he is thinking C. Or maybe C++?!
He does not know either to just learn C or go full way with C++.
He asked me what are they used for and couldn't tell him (its been a while since I last used either C or C++).
So my question, trying to help my friend, is What are they best at, C and C++?.
When you need C++ and when is C enough?
P.S. I am not trying to start a war or argument. I don't want syntax explanations like C does not do templates or does not have classes to better think in OOP etc. I just want to know what are the strongest points of each as applicability, functional solutions
At a very high level, there's nothing you can do in C++ that you couldn't already do in C. The main difference between the two languages is the level of abstraction at which they work.
C is a mid-level systems programming language designed to be a thin, portable layer over the machine's underlying hardware. It's designed to be small, so that the language can easily be ported from one machine to another, but expressive, so that you can build complex systems on top of it. C excels in embedded environments, or areas where resource constraints are so extreme that you need to manually manage all of the details yourself (for example, OS kernels, embedded devices, etc.)
C++ is, in the words of its creator, "a general-purpose programming language with a bias toward systems programming that 1) Is a better C, 2) supports data abstraction, 3) supports object-oriented programming, 4) supports generic programming." It evolved as a programming language with runtime performance comparable to C but with higher-level language features more suitable for structuring large, complex systems. The language is significantly more complex, but is a lot more expressive and maps more naturally to the way that you think about programming problems. While you can get the performance of raw C, often programs in C++ will make small sacrifices in runtime efficiency for simplicity of programming.
I can't think of a single application where C would be strictly better than C++ or vice-versa. C++ programs are on the Mars rovers, internet routers, video games, etc. C programs are what power Linux and Windows. There really isn't a clear winner of one over the other. That said, I'm personally more preferential to C++. I think that it's much easier to encode a design in C++, since the language is richer and you can be more precise about what you mean.
Either language would be a great starting point. Learn C if you want to get up and coding quickly. Learn C++ if you want to invest a little more time, but want to build larger systems.
C:
Support for more weird built-in custom microcontrollers.
C++:
OOP, lots and lots of prebuilt libraries (boost).
Go for C++!
If the goal is just to learn, pick C. It's a very small language, and you can do a lot with it. There are many open-source projects that you can look at for examples of good code.
It's great for making things that need to be deployed as machine-code or language-neutral libraries.
Once you have used C a lot, you might understand why C++ was invented and how you might use it.
Even if you start out with the goal of learning C++, you need to learn a lot of C to accomplish your C++ learning.
If the goal is to learn a lower level language, C++ is considered higher level than C. Might as well go low, since that's part of the goal. If you really want to go low, learn assembly (but not Intel assembly, that's just inflicting pain without benefit). RISC or MIPS styled assemblies are a good choice, but the non-Intel slant probably reduces the hardware your friend has available.
精彩评论