I've never programmed using C or whatever but I use this site a lot so as you can imagine I run into them quite a lot. And due to the fact I don't really understand the languages this is a question Google can't really answer.
开发者_StackOverflowSo in simple terms what are the differences between each of these languages. I assume they are related. All I know is that C++ is what brought object orientated programming to C.
They're loosely related in terms of syntax.
In general, C++ added a huge number of capabilities to C, mostly object orientation and generic programming constructs. However, it did so in a way to try to maintain as much backwards compatibility with C as possible.
C#, on the other hand, is a very different animal. It completely abandoned all attempts at backwards compatibility, and more tries to keep a superficial, syntax similarity to C++.
However, all three languages are very unique, in practical terms. Development is done very differently in C vs. C++ vs. C#, due to the vast differences in supporting libraries and technologies.
C is the grandaddy. When you compile your C application, you get executable byte-code machine code that is ready to run on whatever platform you compiled for.
C++ added Object Oriented development to C
C# is a distant cousin related only by somewhat similar syntax (and the letter C in the language name). C# compiles down into .NET IL that gets compiled Just In Time by the .NET runtime (just like the rest of the .NET family of languages).
C# is not really related to C or C++ apart from the name and using similar syntax. Under the covers C# is completely different to C and C++.
C# was heavily inspired by Java.
C and C++ are the most similar to each other; C++ is almost directly derived from C, adding some new syntax and semantics to support object-oriented programming. Like C, it doesn't offer built-in support for much beyond basic stream-oriented I/O; anything involving bitmap graphics, sound, networking, etc., must be done using third-party libraries. Programs in both languages tend to be compiled and run as native machine code.
C# is much more similar to Java than to either C or C++; like Java, it tends to be compiled to a bytecode that's run in a virtual machine rather than native code, and like Java it attempts to support all the things that C and C++ don't. Java and C# sort of look like C and C++ at first glance (they use a lot of the same keywords, delimiters, etc.), but after playing with them for a while you realize they are very different languages.
Their names look similar because their syntax looks similar.
C is arguably the most different from the three. It is effectively a high-level assembly language that can compile for multiple processor architectures. (Which assembly typically can't)
C++
provides many features in addition to the C
language to assist writing object oriented programs. Any OO program is easily rewritten as non-OOP, even in C++ or C#. The specific OOP features are:
- function overloading: int foo (int); and int foo (char);
- operator overloading
- inheritance
- polymorphism
- templates (technically not OOP-only)
C is the basic programming language. It is great for low level programming and while you can do higher level object oriented programming (OOP) with it, it gets a little "wordy" trying to do so. Great for embedded programming and when trying to make things very efficient.
C++ basically took C and made it into an object oriented programming language. The syntax is slightly different, but overall very similar. This makes it easier to do higher level programming, but still write efficient code at the same time. Good for writing things like game engines. Need to be efficient, but programming without an OOP would be painstaking.
C# is, IMO, the least like the other two. It shares a similar syntax but is almost complete OOP. It is good for writing .Net applications. It is good for quickly writing GUIs, both in windows and web development, in cases where efficiency is less of a goal than trying to quickly get a product to market.
Coming from a C++ background after working in C++ windows applications for about four years and then later making the switch to C#, I can tell you that C++ and C# are very similar in syntax. However C# has some cool shorthand features that are not available in C.
The biggest differences from my view are not in the syntaxm but rather in the libraries, framework or whatever you want to call them - ignoring managed C++. When you code in C++ you will usually have to decide what platform you are targetting as well as what types of libraries you plan to use. When I worked with C++ I used the Microsoft Foundation Libraries. However there are many more options. Also with C++ you have a lot more choices to make as far as what type of IDE you plan to use. With C# you will usually just be using Visual Studio and the .Net framework, unless you are coding using Mono.
Also since C# uses a the very rich .Net framework it is quite easy to begin writing programs that were normally reserved for the gurus in the C++ world. Of course you also have the option of using managed C++ which uses the .Net framework but I would have to ask: why?
I intentionally left out C from my discussion because I have never worked with it at a professional level. I can say this though the little bit of code that I have seen written in C is fuuuuugly. Not just because it is procedural but also because many of the coding standards are very precise but unredable. I don't think it has to be, it just normally is written in a very unreadable style. That could also be due to my experience working with object oriented programming for so long.
Think of C as doing everything in one giant static class in C#.
You pass data around using pointers (you can do that in C#) The thing I find that trips most people up is pointers.
You can create new types by creating structs (just as you can in C#)
If you want to learn C then pretend that C++ doesn't exist :)
精彩评论