C, C++ or C#?
I'm having a hard time choosing which of the C languages I should go for, asking which is best will probably get me nowhere as I bet there are some split opinions on that subject.
But does anyone know the advantages/disadvantages with each one? As in what kind of programs the different languages are better than the other?
I don't really care which is the easiest to learn or anything like that, I might aswell do it the hard way aslong as it's somehow rewarding in the end :p
I know almost nothing of C, I don't know many criticisms of C++ but I don't like C# Not necessarily because it's Microsoft, but it's largely not portable and as far as I know very similar to Java which is portable so I'd go with that.
C++ is my favourite language by far though.
C++. You can do both C and C++ with it.
C++ is all major platforms. That's my vote.
I'm new to C++ and a long-time Java programmer, and as Caducer said, C# is very similar to it (I've studied a little bit of it), I'd say you better off with Java than C#... However, for the little time I'm studying C++, I already think it's much better than Java (hence, even better than C#). And as Todd pointed out, C++ is C-based, so you'll end up learning both. You can't go wrong with C++.
Well the order of fastest running code is: C, C++, then C#.
The order of easiest to use is probably the opposite: C#, C++ & C.
The size of the language (smallest to biggest) would probably be: C, C++, C#.
The portability (most to least) would be: C, C++, C#.
The amount of code required to do a particular task (least to most) would probably be: C#, C++, C.
>I'm having a hard time choosing which of the C languages I should go for
C# is no more a C language than Java.
>But does anyone know the advantages/disadvantages with each one?
C is bare bones. If you want something, you have to write it yourself or find a library that someone wrote for you. Organizing large projects takes a lot of discipline to avoid a royal mess. However, you have absolute control, and that can result in very efficient software.
C++ is only slightly better off than C in terms of available libraries. When you do anything in C++ you're still riding low in the saddle, so don't expect productivity to rival higher level languages. But C++ is as fast and powerful as C. Like C, it takes discipline to organize large projects, but not as much as long as you don't fall into the excessive-OO traps.
C# is tied to a framework if you want it to be useful, and the framework is bulky and slow. However, the framework is very rich, so you can do a lot of complicated tasks with far less code compared to C and C++.
>As in what kind of programs the different languages are better than the other?
C is best suited to embedded systems or riding the hardware where C++ is either unavailable or overkill. C++ is best suited to back-end stuff like frameworks and compilers, or applications that need blazing speed. C# is best suited to rapid development Windows applications or Windows-based web projects that don't need amazing speed.
Probably the best thing really is to learn a bit of each one of them and then decide yourself, unless you have specific needs you would like to share with everyone.
Also bear in mind that programming is only 10% language and 90% programming skill. Yes, C++ is different from C, and C# is not like either of those two - but I have programmed in:
C, C++, Pascal, Modula-2, Fortran, PHP, SQL, Lisp, Assembler (x86, 29000, 68000, VAX, PDP-11, 6502, Z80 and some others) - and it's largely about:
1. Splitting the problem into manageable pieces.
2. Solving the now manageable pieces in that language
3. Presenting the results in a reasonable way.
4. Finding and fixing any bugs in the code.
Most of that is purely ability to understand the problem and solve small and large problems, and only a small part is about "How you express your algorithm in a particular language".
> Well the order of fastest running code is: C, C++, then C#.
I don't know anything about C#, but C++ isn't inherently any slower than C. It CAN be slower, if one decides to take advantage of easier ways of doing certain things in C++ without concern for speed, but that's a choice. The extra facilities can just be unused if need be. Some of them can help speed - for example, std::sort() can be significantly faster than qsort(). So overall I think code can be made faster with C++ than with C, if written with sufficient care.
> The portability (most to least) would be: C, C++, C#.
Almost any platform that has a C compiler also has a C++ compiler. Certain things can be done portably in C++ but not in C90, for example printing types such as size_t that lack a standard format specifier in C90.
I agree C++ can be as fast as C for many things, but overall I think it's just slightly slower than C because it has some extra overhead that C doesn't have like exceptions, constructors/destructors...
Originally Posted by robatino
Yes, any "real" computer can use both, but embedded devices and such may not support C++, so depending on what you're using them for, C is a bit more portable than C++.
Originally Posted by robatino
I think you might mean that when writing "normal" C++ code, it's a little slower than C code ;)
Originally Posted by cpjust
But if you write C-typical C++ code, it's as fast or faster than C, depending on the algorithms you use.
I'm not sure what you mean by "C-typical" code?
C code within C++, so to speak. Code where you mess around with pointers and arrays instead of std::vector and std::string and shared_ptr, etc.
Well in that case you're not really using C++ are you? You're just compiling C code with a C++ compiler.
Originally Posted by Elysia
Not really. As long as it is part of the current standard defined for C++, it is C++. The language is clearly defined in the standard.
Originally Posted by cpjust