An argument has been raised in my class regarding C and C#.
I sta开发者_C百科ted that it's correct to say that C & C# are the same (meant: same by functionality, but not by concept).
Different by concept: C# meant to be easier to program with than C. C is more descriptive. Same by functionality: Everything you make with C# - you can also make with C (including OOP).
Is that right?
Edit:
While reading the answers I noticed that my question is not clear.
Please refer to the syntax of the languages. As if I were asking: would it be significantly easy for a C programmer to learn C# or it would be like a whole new language (like assembly which is significantly different)...
In that sense I would say that C and C# are pretty much the same.
(sorry for the unclarity)
Well, they are both Turing complete.
C is a general purpose language aimed for System Programming.
C# is a general purpose language aimed for Application Programming.
Both provide the tools to do the desired job better than the other in its own area. So, no they are different.
@Don I think I have to clarify my answer.
When you said:
C# meant to be easier to program with than C. C is more descriptive.
Wrong, It depends. For an operating system programmer I would say that C would be easier to play with. Even Singularity has some parts written in C.
Same by functionality: Everything you make with C# - you can also make with C (including OOP).
Again, could you tell me how to write Lambda in C?....
At the end of the day, both are Turing Complete which means, that anything can be computed using the first, can be computed using the second. I didn't understand the question as an exercise in computing theory, sorry if that was the meaning of the question.
If you want to get down to the nitty-gritty of it, the vast majority of languages used for programming are capable of doing anything done in another language. There's a specific term used to describe this, Turing Complete, which when applied to a language means that any problem that is computable can be solved by that language.
That being said, there are significant differences in the proper ways to approach problems that lend themselves to certain approaches. C is primarily designed to offer useful language constructs while still maintaining a close relationship to how computers work internally, and is more suited for procedural development. C#, on the other hand, is a much higher level language that has a much higher level of abstraction, signficant abstraction of memory addressing and management, and built-in support for OOP and some functional constructs.
There's nothing that can be done in one that is impossible to do in the other (including procedural programming in C#, or OOP or functional programming in C), but the design of the language lends itself to a certain style.
That's not entirely true. C# and C differ in that C# requires an underlying framework to compile against. Even if you were to strip away the standard C libraries, you could use pointers to memory to call the operating system or even low-level hardware. C# is a managed language and as such requires something to take care of its memory management, such as its garbage disposal. (When was the last time you told C# when to delete an object?) C is an unmanaged, low level language.
Try writing an operating system in C#... it isn't possible. Even if you were to compile C# to machine code rather than MSIL, first you'd have to write a manager in another language that could address the management issues of C#.
You need to ask yourself how much this question actually matters. It is neither fair nor useful to compare languages with completly different design goals (Read Soustroup's C++ FAQ for a treatise on this topic regarding C++).
Many other answers refer to Turing Completness as functionality: I don't believe that this is really helpful. Albeit being the theoretical foundation of programming languages abilities it is no indicator for fitness of any language for a particular task. I'd rather look at what the libraries and language concepts enable you to achieve easily (Application and System programming respectively).
Regarding paradigms: You can write in the same paradigms in both languages but each of them makes it easier in what they were designed for. (This is true for a lot of languages.)
After all, I don't think the answer to your question is of any relevance.
I would say that they are both procedural languages. C# has OOP features as well however. But this both procedural bit makes them very similar and dealing with problems in them very similar.
Though, C# is more multi-paradigm because C# has lambda expressions(and thus anonymous functions) so it has bits of functional programming(including the foreach) and has a much more strict typing system than C.
So I would say C has the same functionality as C#, but not the opposite. (unless you count low level programming as part of functionality)
That's absolutely correct.
You can even extend this to all languages as everything that can be done with one turing-complete language can be done with another turing-complete language...
And C and C# are turing-complete of course.
As long as languages are Turing complete you can accomplish the same tasks in them so they are what you termed "same by functionality" - generally, everything you can make in x you can make in y.
However, outside of this broad generality, I wouldn't call them "the same" - because there are differences - C is completely compiled and C# runs inside the CLR - that means you can write low level things like bootloaders, OS, etc. in C but couldn't in C#. (Technically, you could make a fully compiled version of C# and write an OS in it, or make C run in the CLR - but that's not how things are currently implemented.)
Why? Because there's a "C" in both of them? C is a procedural programming language and C# is object oriented. C has explicit memory management and C# has garbage collection. These two features alone mean that the two languages are pretty far apart, having much more in common with other languages than each other.
Short question, short answer.
For anything except hardware, sure, C and C# are functionally equivalent. For dealing with hardware, if you need more functionality than C# offers, C wins.
精彩评论