views:

408

answers:

11

An argument has been raised in my class regarding C and C#.

I stated 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)

A: 

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)

Earlz
Functional and OOP paradigms are entirely possible in C - there's no built-in constructs for them, but it's entirely possible to implement via convention.
Ryan Brunner
Well yes, it's possible to do that in any language. I mean that C# has built-in syntax things for both already built in. Also it has reflective programming, which I'm not sure how you would manage to do that in C without dropping to assembly or something like that.
Earlz
@earlz, well, clearly you can implement reflection in pure C by re-implementing half of C# in C, including a `struct c_sharp_object`, and then having functions which operate on that struct to extract metadata. This is all people mean when they say, "You can do anything in C". It doesn't mean you can have reflection on arbitrary C structs, just that you can build an object system which has reflection. Likewise you can do functional programming just by not writing any functions that have side-effects. But the compiler won't enforce that for you.
Steve Jessop
Yea.. I understand that.. just.. idk.. seems dumb to try to do such a thing in C when other equally good methods map better to the language and are faster.
Earlz
Sure. There are valid potential reasons, but it'd be hard to get enthusiastic about building an object system with reflection for C, until you know which particular reasons make C the best language choice for a particular problem, despite it lacking these features that the programmer apparently needs to use.
Steve Jessop
+13  A: 

Well, they are both Turing complete.

Randy Proctor
Well, Bf is Turing Complete, that doesn't make it functionally equal to C# or C.
AraK
In the sense that "anything in C/C# can be done in BF, then yes, absolutely it means that. Obviously BF rarely, if ever, is going to be the most effective tool for the job, but it's always possible.
Ryan Brunner
doesn't it? Why not?
jalf
I'll never understand this point. Programmers have requirements which are much more specific than "programming a Turing machine". So it's great if Brainfuck or whatever language is Turing-complete, but why should I care?
Bastien Léonard
@jalf They are equal in *concept* in the sense that you can express any computation in anyone, but not in functionality, are they?
AraK
The key thing to remember here is that a Turing machine is capable of computing everything that we know to be computable (it's obviously not a very effective tool to use though :) ). So if a turing machine can do everything that can be computed, and language X is turing-complete, language X necessarily can do everything that can be computed.
Ryan Brunner
Note however that Turing completeness is a very paltry goal for a language. You don't just want to compute computable functions, you almost always also want to control hardware. A Turing complete language(+libraries) cannot necessarily open a socket, or read a serial port, or alter your monitor's power-saving mode. Just because two languages are Turing complete (subject to resource limits) does not imply that everything you can do in one language can be done in the other. They may have different resource constraints and different hardware interface capabilities.
Steve Jessop
And that's before you consider that "doing something" in a particular language might refer to the source as well as the output. If "something" is "write a hello world program in X characters", then there exists an X such that I "can do it" in Perl, but "can't do it" in Java. Turing ignores this kind of "something". Such concerns are important to programmers, but not to proofs of formal functional equivalence. The questioner's edit redefines "pretty much the same" to do with the appearance of the source, not formal equivalence. The statement, "C doesn't have closures", has meaning.
Steve Jessop
A: 

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.

Nils Pipenbrinck
A: 

The Linux Kernel is written in C, not C#. One of the many reasons that they are not even equal by functionality.

Amit
Um, could you maybe elaborate on why C is superior? It's my opinion too but just because Linux was written in C doesn't mean C is the best; otherwise we would surely have a lot of people touting COBOL is the best because a lot of big software was written with it many years ago
Earlz
+1, nod... I don't see any OS written in C# any time soon. Must be some reason...
David B
@David B:http://channel9.msdn.com/shows/Going+Deep/Singularity-A-research-OS-written-in-C/...?
Dor
I can find useful software written in a whole variety of language, so unless you can establish the Linux kernel as the predominant achievement since the beginning of software, this isn't a convincing argument.
David Thornley
@David: Here we have pitted C against C#. I will remove the superior part. But, still can we call them functionally equal ?
Amit
Good to hear people say this. If you do your application development in C and I do mine in C# it meas I'll get so many more features done that there will be no competition! More of this attitude!!
erikkallen
@erikkallen: Each has its own niche
Amit
+12  A: 

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.

AraK
...and excluding the implementation subject?Also please refer to:http://channel9.msdn.com/shows/Going+Deep/Singularity-A-research-OS-written-in-C/
Dor
You can have a kernel written in any language, even something like QBasic. But really? Which is easier to program with? Something where you must hack around in order to deal with pointers, or a language that supports pointers? (C# supports pointers with the unsafe context I know.. but still.. ) Any language can write a kernel, as it's turing complete. It's just a matter of how much bootstrapping you want for the language to run on bare metal(in C, all you must do is get a stack setup. In C# you must have a .Net interpreter)
Earlz
"Again, could you tell me how to write Lambda in C?"No, but that's not the point. I could create identified function, which might be less convenient.I changed my initial post, please see it.
Dor
+4  A: 

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.

Ryan Brunner
A: 

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.)

Nate
C# is "just-in-time" compiled to native code by the CLR. Also, C# does support pointers and non-managed memory, but such code must be enclosed in an "unsafe" block. (That is the actual keyword in C#. Makes sense to me.)
Cylon Cat
+2  A: 

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#.

David Pfeffer
Just a quick note that you somewhat addressed that C# does not necessarily imply a managed runtime. Obviously, in common usage, C# implies using .NET and Microsoft's compiler, but C# is a standardized language that doesn't necessitate MSIL.Technically, it should be possible to write a C# compiler in C# that can handle memory management. Keep in mind that pointers and manual memory management is actually a feature of C#, although it's not widely used.
Ryan Brunner
And you will have to write ASM to address the issues of C.For C#, the manager could have been embeded in the bits by the compiler.
Guillaume
"Try writing an operating system in C#." Have to DV you for that, Microsoft already has written an operating system in C#, it's called Singularity.
Chris Marisic
The compiler can't handle memory management. It can provide code that runs along with your code that will handle memory management, but that's not compiling anymore, that's linking against a "standard" (albeit non-Microsoft) library. My argument is that C does not require any standard library. And while C# does contain unsafe code abilities like pointers and manual memory management, that doesn't dismiss my argument that you wouldn't be able to use the managed functionality of C# without a manager. The argument was that C# was equivalent, not some derivative language that excludes features.
David Pfeffer
+2  A: 

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.

pmr
A: 

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.

quillbreaker
C is functional programming language?
Amit
C#'s built-in garbage collector equals C's garbage collector library that someone can create...Ain't C is ObjectOriented-like? (applied with structs)
Dor
@Amit sorry. procedural programming language.
quillbreaker
A: 

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.

Dean J