开发者

What does C++ add to C? [closed]

开发者 https://www.devze.com 2023-01-08 04:26 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

What does C++ add to C?

  • What features of the language are the Clang/LLVM projects, the parts of GCC that are being written in C++, chromium, and any others all taking advantage o开发者_Python百科f? What features are they avoiding?


Like all sophisticated and powerful things there is a price to be paid to succeed in C++.

  • You have to be incredibly careful with memory management.
  • Multi-paradigm capability means you have to be really good at design to avoid making a mess.
  • Extreme performance requires careful planning and selection of features used.
  • The ability to circumvent most every language policy requires monumental self discipline.

So if you're sloppy with memory, poor at design, don't need fast programs, or have no self discipline, then please don't learn C++. There is always Java or C#.


meta programming? templates?

like with C you get performance, but the code looks horrible. with the high level languages you get nice code but there is less flexibility to make the fastest possible code.

with c++ you can do both? you can freely make anything as fast as it could be made in C, but native object orientation, and templates/operator overloading ect makes it so you can write fairly nice looking code too. indeed, you can make it so it is neat and fast.

I have never really found it more of a pain to write stuff in c++ than in a higher level language. the trick is having good libraries.


Because despite academic efforts such as Singularity, there's not a single mainstream OS where drivers can be written in a high-level language.

Note that anything that can be done in C++ can also be done in C, but some things are a lot easier in C++.


Not? I would say it's not worth if you performance is not an issue for you. (Follow the double negatives.)


My two cents:

  • Although I don't program in Python, I would have to say that Python is probably the best programming language for getting real work done. It's an elegant language, and it has an enormous collection of libraries for doing various things. However, my experience as a user has shown me over and over again that Python is slow (take yum, for example).
  • I do know Haskell pretty well, and I have to say that it's a friggin' awesome language. Better yet, it is compiled, and its speed is competitive with Java and C++ (though you have to put forth extra effort to get this speed in some cases). However, libraries for things like database access don't always match the elegance of Haskell's base libraries (I'm probably way wrong about this), and they're harder to install on Ubuntu. In my opinion, that's why it's more challenging to get real work done in Haskell than in Python.
  • Ruby's good for web applications. Other than that, it's slow (though I speculate jRuby or something might be faster).

C++ is far from elegant, and in many cases, elegance is frowned apon. Anyone ever told you to use static_cast instead of C-style casting? Anyone ever told you not to use namespace std;? C++ has a lot of features, but doesn't tend to have many important language features (such as closures, which are formally proven to be the best thing since sliced bread).

Why do people use C++, then? Well, it's performance-focused, making it a good choice when you need speed. It has classes, namespaces, and templates, so it's a good choice when you want better code organization, but still need to use "C" for some reason. Also, it has the Boost library, which I've heard is really good for getting work done.

0

精彩评论

暂无评论...
验证码 换一张
取 消