If I got it right C# is basically meant for the Windows OS. But what are the differences exactly between C and C++ and what would be better to learn?
Printable View
If I got it right C# is basically meant for the Windows OS. But what are the differences exactly between C and C++ and what would be better to learn?
You should learn them both. Lots of common aspects between C and C++.
Agreed. If you are going to learn either C or C++, you might as well learn both. They are used heavily together. C code is very often mixed in with C++ code, especially in legacy code if you ever have to go and read legacy code for any reason.
C# is primarily for Windows, but it has been ported to Linux as well. I assume since it has been ported to Linux, you can also write C# code for for Mac OS X...but that is pure speculation on my part.
Learning both languages is silly. You want to learn either. When learning C++, you would also like to learn something of its low-level basics, which is normally inherited from C, but with some differences.
What to choose? Well, aside from the whole what you like best argument, for anything but stubborn integrated platforms, I would choose C++ simply because it is much more powerful and flexible than C, and is a more modern variant of C.
On the other hand, however, C++ is still very bloated and slow by comparison. So, if you desire to go into embedded work, I would recommend C. And, BTW, C is more powerful than C++ and is the modern language of choice (in certain circles).
I guess the point here is that it is asinine to say "C is better than C++" or "C++ is better than C" as each has a place in the world. No one language is complete enough to handle EVERY task easily (though almost any language could handle any task -- just may not be tooled for it).
I can already see where this thread is going. Another C vs C++ debate incoming...
More accurate to say the C# is primarily for the .NET platform, which is primarily for Windows. It was intended to be a multi-platform virtual platform, like Java, but in practice that hasn't really happened. Mono, exists, which is a Linux implementation of the .NET framework, and apparently it's improved greatly over the years. But unless I'm horribly out of the loop, it's certianly not mainstream.Quote:
C# is primarily for Windows
In any case - comparing C# to C and C++ can get kind of silly, anyways. I also think that C and C++ are diverging more and more, it used to just be a matter of having classes and not having classes, but now they have two extremely different styles.
Hehe. Yes, it always turns out that way, does it not?
But right now, I have some myths to bust. C is not better than C++. It is not faster than C++. Bloated is subjective. I would prefer to see it packed with a lot of useful features.
C++ is as fast as C, or faster. C is also just as fast as C++, or faster. It depends on how you use it and where.
And while you say is more a powerful language choice in certain circles, I find that to be a very bold statement. Sure, C is preferred in certain areas, but I do not know if I would exactly call it a modern language or more powerful. Usually there is a reason for C, but more powerful? I simply do not know.
But the point I was trying to make is this: C++ will usually get the work done faster than C, so it gets the upper hand (this may change depending on experience, of course, since it is subjective), so if there is a choice between learning C and C++, C++ is usually the better choice IMHO.
Of course, this also depends on where you want to write your code. Embedded systems usually only have C compilers. API is still C or Obj-C, but is still accessible from C++.
It is simply a choice of preference.
It is, if you make it obvious your post looks like irony, which it did not.
So it basically comes down to the following questions.
1. Is there anything in C that you can not do in C++ or the other way around.
2. Would that one be best to learn then when you just want to write basic programs to begin with for a Windows or Linux platform?
1) Yes, there is plenty that can be done in C++ that cannot be done in C (or at least not in any easy and fast way). I know there are a few things that C can do, but C++ cannot, such as variable-sized arrays, but aside from that, I am not really sure. Regardless, C++ has the big upper hand in this question.
2) I would argue yes. If you use the high constructs of C++, it is very easy to get started writing simple programs. I especially like Accelerated C++ which demonstrates such a way. Using C, it would take a while to get started due to its lower complexity. However, that complexity also exists in C++, but usually it can be abstracted using higher-level methods and/or functions.
If you're just writing basic programs, I'd choose C++ and learn it as C++ (and not C with classes as many books/tutorials teach).
But either choice would be fine.
Networking libraries are plenty for both.
As much as I like to believe in the omnipotence of C, could you explain that a little more? I think you're making a generalization that I'm not catching.Quote:
you cannot write a real world application without C
>> Learn both.
You can absolutely write a real world application in C++ without learning C. Sure, learning C++ entails learning some (or even many) aspects of C, but that's different than learning the C language.
A language is more than just syntax. It is techniques and best practices as well. Learning both is an interesting and worthwhile endeavor, but it is hardly required to use either effectively.
I second both. Anyone silly enough to think just learning C++ and ignoring C will get them through is a fool. "Oh rats, the library is in C, I'm not using it". Why wouldn't you learn both? They're not the same language, but they're very similar in syntax. Knowing C++ doesn't make knowing C any less useful.
@Elysia, C is just as 'modern' as C++. OOP is not "the answer to the universe", you'd find C++ violates (or allows you to violate) many principles of SE, friend classes -- please, connascence abuse anyone?
It has a bigger standard library you say? Why is it then Boost is such a large dependency for many projects? And yes, there exist libraries that give C much, much more "standard" utilities. Such as glib.
Perhaps he means without C API calls? Still, I fail to see how you need C to write a real-world application?
I think you're confusing the definition of learning C++. It doesn't mean ignoring the C aspects of it, it just means not learning all the details specific to how to get things done in C.
I mean, I took a class in C 14 years ago and promptly forgot it. I haven't written anything in that language since. And I've gotten through as a professional C++ programmer just fine.
> But what are the differences exactly between C and C++
C++ provides OOP built in, exceptions, templates, and a standard library built around those features. Everything else comes from C. For example, as you would have to manage memory in C, you have to manage memory in C++, unless you use "smart pointers" which are pointer-like template classes. Being that is the case, it is rather underwhelming that the standard (I'm referring to C++9x, the version you will probably learn to use yet) only provides one type of smart pointer -- auto_ptr. If you need a smart pointer that does something different than auto-ptr, you have to use a third party library or write the class yourself.
> and what would be better to learn?
It's basically a pain to learn either so it shouldn't matter where you start. I learned C++ first just because I found this place, and that's not a good reason.
If you've never programmed anything before, then you have a very different task: you must first learn how to program. Newbies are better suited to learn how to program on an interpreted language I think, because interpreted languages run all of the code on demand and there is no such thing as memory management. They do more with less coding time. Otherwise, as Mario puts it, "you have to inspect every dark corner of the language." Memory management should not be what programming is.
Or at least, learn how to program before we zealots tear you up discussing our opinions on what you should know.
I think that is a good idea. I did some basic work before in Python and VB.NET and have some experience in web application development but this here is all new to me.
It will probably take me some time to figure everything out but I will start with getting a understanding of C. I found a website in my native language that discusses it and offers tutorials and assignments. And then move on to C++.
Thanks for all the answers from people here (read them all). But I think best for me is now to leave this topic for what it is before I end up with a brain injury from all the used terms. :eek:
That is just the thing - learning C before C++ is silly. C++ is completely different. Yes, it has some C aspects that you are going to have to learn, so you will learn C. However, C++ does things in a completely different way, and with a different way of thinking, so learning C first will not only be painful, it will also hinder your intake of C. Once again, they are two different languages. Learn one, not both, preferably.
I think Daved nailed this one:
It means do not learn C. Learn C++ with its C parts. It is a good idea to be able to implement lower level code.
OOP is not C++'s only feature. But the point is that I would call C++ more modern because it allows us to do things faster and easier than C, while still allowing to do things the low-level complicated way, aka C. OOP and other things are also modern things that modern languages feature simply because they have proven to be useful in situations. Why then not allow us to take advantage of this? Why should we be limited?
I am also half-tempted to say that Java is not a modern language, simply because it is limiting and lacking in so many ways compared to C++.
Since you said "you" I will have to disagree. It absolutely depends on the way one thinks. If one thinks in a top down design, then one should use C. I personally have never grasped the idea of "do this to yourself" and am more of a control freak than that. This is also why my OS of choice is Slackware GNU/Linux in place of other flavors and MOST ESPECIALLY in place of Windows (though I use WinXP for gaming). I would much rather control my on fate than to leave it up to the language to handle that for me. I want control. I get it with C. I don't feel like I'm in control with C++.Quote:
Originally Posted by Elysia
Which is why, as I stated before, it is asinine to say "C++ is better than C" or the other way around. I mean we may as well argue whether Chili is better than swimming. There is no comparison -- Chili is WAY better.
EDIT: "There is no comparison -- Chili is WAY better." would be ironic <=== Have to put this disclaimer in for some.
I have stated that C++ is more modern than C. I did not claim C++ is better than C. Obviously this is subjective.
Would it be easier for one with a programming background in .NET to start with C++? Yes, it would.
And obviously, the whole point of C++ is to give you the tools to get the work done in the fashion you want or require.
Oh, my bad. I equatedwith C++ is better than C as I take the phrases "more modern" and "do things faster" as implication of greater worth. Perhaps my understanding of these phrases does not coincide with the rest of the world.Quote:
Originally Posted by Elysia
>If I got it right C# is basically meant for the Windows OS.
C# was designed with .NET in mind, and .NET was designed with Windows in mind. However, both C# and the foundation of .NET (CLI) are standardized such that they're not tied to Windows.
>But what are the differences exactly between C and C++
I think this question implies an intersection that one shouldn't assume without proficiency in both languages. The differences run deeper than language features, to the point where actual code in C has only a superficial similarity to actual code in C++. It's safer in the beginning to pretend that C and C++ are unrelated, yet have similar syntax for some fundamental features.
>what would be better to learn?
I wouldn't presume to tell you what you should learn, but I will say that I've never regretted learning C. I believe that a firm understanding of C and the challenges involved in writing software with C have helped make my C++ better. My advice is to learn the basics of one before learning the other, but ultimately learn both. Learning C and C++ at the same time (or any two languages as the same time) strikes me as an exercise in frustration.
Which is about as valid an argument as the most efficient OS kernels in the world being written in C and their mailing lists abhorring C++. That sector of the industry has made their choice for certain reasons, but it has absolutely no bearing on "which language is better", or "which I should learn" unless the person asking the question specifies a LOT more about what they want to do.Quote:
OK, but seriously, there IS a reason why games are written in C++ and not C, right? Perhaps we should ponder about that.
>OK, but seriously, there IS a reason why games are written in
>C++ and not C, right? Perhaps we should ponder about that.
It's easier to organize large programs in C++ than C? Then again, it's probably just as hard to organize them well, so I suppose games are written by the lowest common denominator. The many critical bugs I encounter in the games I play is proof enough that game programmers are not as good as we'd like to believe. :D
In reality, I think the hype of OO kind of killed C as a viable option for most new software. It doesn't mean C++ is any better or worse, just that the current generation of developers has been trained to see OO as the single most important aspect of high quality software.
Of course not, but I think it would prove that for such large scale performance projects, they chose C++ for a reason over C.
Because in some stuff C++ has an edge over C.
Let us summarize some key traits of C++ and C.
C++:
+ Much more functionality and flexibility than C.
+ High-level abstracts that makes it faster and easier to create certain type of code.
+ More beginner friendly than C.
- Not as portable as C.
C:
+ More portable than C++.
- Not as much functionality as C++.
- Less beginner friendly than C++.
Feel free to add or disagree with certain cons/pros.
I believe (not being one myself) that many game companies have library packages that are written in C -- For the fast graphics libraries, is this not so? Are there not wrappers for these "low level" functions for C++? <<== Now, this is purely speculation as I am NOT a game programmer, but I believe that the majority of packages I have seen are based upon OpenGL and/or other such libraries. If I am misinformed on this matter, please correct me.Quote:
Originally Posted by Elysia
>+ Much more functionality and flexibility than C.
Since it's really a perspective thing, I'll restrain myself from disagreeing with this. :)
>+ More beginner friendly than C.
I'm not sure I'd agree with this as a blanket statement. C++ has more "magic" going on which is distinctly not beginner friendly. In terms of being able to do more right out of the gate, C++ probably is more beginner friendly, but it also requires more faith. You might want to qualify this particular pro of C++.
My starter language was QBASIC (with the line numbers) -- then the "real" first language was Pascal. C was still fairly new and didn't have a widely published standard (late 80's). C++ wasn't around until much later for me. I tried it but could never get a "warm and fuzzy" about the way I/O was handled -- What the CRAP is this cout/cin thingy anyway. I found, however, that I could still use my good ole printf/scanf. Now, that I can use these in C++ is pretty cool, but, am I not still writing C code just with a .cpp extension?
For me, C was VERY beginner friendly since it was the 3rd language I learned (the second was i386 assembly). C++ was a major jump for my thought processes and completely was against the way I know to do things.
Also, both C and C++ are extremely portable -- I don't get why you think it isn't?
> + High-level abstracts
CONFUSE THE SNOT out of me. I cannot stand it. Let me deal with the trees, then I can take care of the whole forest. Don't make me just look at the forest not the trees.
> + Much more functionality and flexibility than C.
Pass me that crack pipe when you are done.
You cannot truly believe this? Neither is more or less functional than the other. Whereas you may not be able to make C do things you want it to do, I can. On the other hand, I don't know that I could successfully write a "hello World" in C++ ;).
It is completely a matter of choice -- this goes back to that thing of you cannot compare these two like that, nor any other language. It is purely a matter of preference.
People, people, people. This is truth. It has more functionality and flexibility than C.
Now, whether you want or need it is another thing entirely.
Saying that c++ does not have more flexibility and functionality than C is like saying that assembly has more functionality and flexibility than C.
Right out of the box, for a newbie for programming, I would definitely call C++ easier since they do not have to worry about the low-level stuff right off the bat.Quote:
>+ More beginner friendly than C.
I'm not sure I'd agree with this as a blanket statement. C++ has more "magic" going on which is distinctly not beginner friendly. In terms of being able to do more right out of the gate, C++ probably is more beginner friendly, but it also requires more faith. You might want to qualify this particular pro of C++.
Yes, they are, of course. But C is more so than C, since there are some platforms where a C++ compiler does not exist.
You are not required to use them, but the functionality being there is a not bad thing. It is a good thing in case you need it.Quote:
> + High-level abstracts
CONFUSE THE SNOT out of me. I cannot stand it. Let me deal with the trees, then I can take care of the whole forest. Don't make me just look at the forest not the trees.
Neither is more functional than the other, but C++ has more functionality built into the language. Classes, for example, are supported natively, while they must be emulated in C. Hence C++ has more functionality. This does not mean it could not be done in C with some more work, however. But some things, like templates, are difficult, if not impossible to do in C.Quote:
> + Much more functionality and flexibility than C.
Pass me that crack pipe when you are done.
You cannot truly believe this? Neither is more or less functional than the other. Whereas you may not be able to make C do things you want it to do, I can. On the other hand, I don't know that I could successfully write a "hello World" in C++ ;).
Do not get me wrong. They are a matter of choice. Neither are better than each other in that sense. But language-wise, functionality-wise, would you not say something is better than the other?Quote:
It is completely a matter of choice -- this goes back to that thing of you cannot compare these two like that, nor any other language. It is purely a matter of preference.
Like an electric screwdriver is probably better functionality-wise than a normal screw-driver, but it does not mean it is the best tool there is. That is subjective.
Quote:
Originally Posted by Elysia
So, is the word contradiction in your lexicon?Quote:
Originally Posted by Elysia
>People, people, people. This is truth. It has more functionality and flexibility than C.
Then define what you mean by "functionality", what you mean by "flexibility", and prove it. Stomping around waving your opinion and calling it truth without any substantiation isn't productive, especially when you use ambiguous terms.
>Saying that c++ does not have more flexibility and functionality than C is
>like saying that assembly has more functionality and flexibility than C.
Actually, that makes perfect sense to me. C has the same depth and breadth as C++. Thus, they are equally functional and equally flexible. Assembly has slightly more depth than both C and C++, so it is slightly more functional but equally flexible. Next!
*shrug* Then what is the point in expanding what I mean? I will just leave it be.
Use C I/O functions all you want, but remember that there are some cases where they leave you helpless (in templated code because of the type safety thing).Quote:
I tried it but could never get a "warm and fuzzy" about the way I/O was handled -- What the CRAP is this cout/cin thingy anyway. I found, however, that I could still use my good ole printf/scanf. Now, that I can use these in C++ is pretty cool, but, am I not still writing C code just with a .cpp extension?
I see C sometimes favoured by beginners, and the reason is that higher levels of abstractions are harder to get, so because of the understanding issues they'll find it easier to do things the hard way. Similarly, beginners tend to find it easier to use goto and all globals instead of structured control statements and argument passing / return values.
Assembly DOES have more functionality and flexibility than C. You can't write a boot loader in C. You can't specify the arrangement of data within a struct in C.Quote:
Saying that c++ does not have more flexibility and functionality than C is like saying that assembly has more functionality and flexibility than C.
Then you are misinterpreting my words.
Fair enough. What is your definition of the word flexible and functional, then? I get that C++ generally deals with a higher-level of abstraction, but that really has nothing to do with flexibility and functionality. You can implement closures in C, you can have an OOP style in C, it all depends on the programmer.Quote:
Then you are misinterpreting my words.
...and the single biggest excuse for slipping deadlines.Quote:
...OO as the single most important aspect of high quality software.
Perhaps I was.
What I meant is that C++ have things such as templates, OOP, classes, etc, etc.
Yes, you can emulate these in C, but it is not as easy as if they were natively supported. So if you do not have to invent a solution to get it working right, it might be safe to say that it is faster, usually easier and less error-prone to use them than to emulate them.
Assembly supports even less of such things than C. It does not even feature high-level syntax and statements such as ifs.
This is what I meant with C++ having more "features".
I think of it as having more tools available at the tips of the programmer, allowing us to get things done faster. The later part is subjective, of course.
I really don't think we got anywhere.
I don't think anyone disagrees with what this means at face value, but that does not make C++ more functional and flexible than something else, depending on what you need:
You know, given that he acknowledges everything you just said, I think you missed his point.Quote:
I get that C++ generally deals with a higher-level of abstraction, but that really has nothing to do with flexibility and functionality. You can implement closures in C, you can have an OOP style in C, it all depends on the programmer.
And to wit, most of the benefit from learning C++ first comes from using stuff like the STL early on, which is actually not the approach people seem to encounter. Even if I'm wrong about that, there is a whole widget for cleaning up STL related errors, so I don't find that to be very newbie-friendly either.... like I said, it's a pain.
I don't think it's fair to discuss features of X versus Y when we were originally asked a question about learning something. C++ does throw a lot at you, and in a weird way.
I can't believe I missed this!!!!!
On the other hand, one could argue that this is better than nothing.Quote:
And to wit, most of the benefit from learning C++ first comes from using stuff like the STL early on, which is actually not the approach people seem to encounter. Even if I'm wrong about that, there is a whole widget for cleaning up STL related errors, so I don't find that to be very newbie-friendly either.... like I said, it's a pain.
(For which reason I wouldn't recommend neither C or C++ as the first language to learn – and if you have some particular applications in mind, you might still consider whether they are a good choice for that.)
But anyway, STL errors are for wuss's. Try some boost errors (does the tool help with those too?)
Haven't we matured past these debates yet?
Linux owns windows!
Hehe. Nice.Quote:
And I'll add my piece because the exact arguments used so far to convince the OP to go for C++ have done quite a great job at convincing me to go C#.
Someone should add a rule that C vs C++ debates are not allowed on CBoard...
By my view C/ C++ both are accurate and fast if they are used with full of there potential.
But my vote goes to C because of its simplicity and closeness towards hardware.
While you people debate on what's silly and what's not, I got a couple of questions...
1) Is learning C, then C++, the best way to go ?
2) When you say learning them both is silly, do you mean learning both at the same time ?
3) When you say learning them both, do you mean learning both at the same time ?
Thanks!
I guess everyone will give their own answer, but based on watching this same debate here a bunch of times, my impression is that people are (mostly) presenting the way they learned as the way to learn.
A couple of things are clear:
- if you want to learn C++, you do not need to learn C first. Just start studying C++.
- if you want/need to program in both languages, you might as well study both of them. You could do that at the same time, or consecutively, according to your fancy.
- since C++ includes most C syntax (altho there are some small differences), once you have this basic syntax down, the difference between the two will be about how you use the syntax to accomplish a goal. Related to this is the use of common libraries, which differ.
Then should one then learn Assembly, then C, then C++ then ?
Just go! ;)
Why? You do not need to know assembly.
Actually, you do not need to know C or C++. If you would like to learn one of these three, study it. They are not prerequisites for each other. If you would like to learn two, study both of them. If you would like to learn all three -- well, that should keep you busy for a while, anyway. :p
I was just reminded of my all-time favorite Linus Torvalds quote:
I really like that - because it's exactly what I like about C. A good C programmer ought to be able to look at any construct and have a good idea how that command would be represented in Assembly - and yet you can combine those constructs into a higher-level programming style. I think that makes it the perfect OS language. Using it for a user-friendly end-user app, however - is probably not the best choice - but one that I think everyone should at least be able to understand.Quote:
Some people seem to think that C is a real programming language, but they are sadly mistaken. It really is about writing almost-portable assembly language
Of all the people I've met who would feel comfortable writing an OS/kernel in C, I can't say that any of them struck as being a good interface designer! The difference I see is that in one you're basically writing an interface to control the hardware, and any advantage counts, where as in the other you'll probably err on the side of faster development, and you're more likely to take a much more OO approach and use a language that lends itself to such a purpose. Additionally, I sometimes find that the libraries you use affect the "style" and feel of your code just as much as the language you choose.
Yeah, faster development (vs. "performance") I could see as a factor, if you mean opting for a much higher level oriented language. But I don't think using C will lead to an inferior interface, that is really up to you. An "OO approach" could just as easily lead to gimpy cookie-cutter style stuff.
Probably, but if you are talking about, eg, GUI libraries, etc., most of those are available for multiple languages. The "style" of the library is a constraint, but that is independent of the language. Of course, C is a little shy on libraries like this, but I think most of the major ones (gtk, SDL, etc) are there.Quote:
Additionally, I sometimes find that the libraries you use affect the "style" and feel of your code just as much as the language you choose.
Recently I made an ncurses app for a site I work on, to make it easier for me and a few other people to accomplish certain routine tasks on the server. Ncurses is pretty much state-of-the-art when it comes to terminal apps :) -- the work is done via ssh login, so no GUI. But I didn't use the C library, I used Curses::UI for perl, which is a OO library. Totally, the factor there is development time. And the perl library contains things like ready-made widgets that are not part of the base C library. However, I believe there is a parallel Curses "user interface" lib for C.
I think I would have ended up with the same thing either way. Possibly, the C version might have been slightly better because I would have had to make a text editor widget myself, to my own specs. As is, the ready-made one is fine, but it is not EXACTLY what I would have done, if I had to do it myself.
Also worth note: virtually the entire GNU OS (aka linux) including the GUI front ends are in C (they also like python). Linux is I guess not traditionally known for user friendliness, but really there is nothing wrong with most of the individual apps...
Yeah - I agree with that. You definitely can make an excellent interface in C, and I generally like the more linux-y interfaces - but that's because I choose functionality and keyboard usage over animations and effects any day. I'm just saying that if your primary purpose if making a nice interface to a typical program, C probably wouldn't be your first choice unless your were already intimately familiar with it - like most of the GNU folks, I'm sure!Quote:
But I don't think using C will lead to an inferior interface, that is really up to you. An "OO approach" could just as easily lead to gimpy cookie-cutter style stuff.
C || C++?
I guess it really depends on how far you want to go with programming.
If you want to learn computer science, C is by far better choice. Mostly because it's so transparent, easy to translate to machine code in your head (some call it "portable assembly").
Also its strong relationship with Unix and Unix-like systems....all the code, manuals are written in C...so if you want to study OS....C is the way. Then there's just a large amount of code out there written in C..it's syntax is practically used as pseudo code in many books, tuts...
Also, it makes so much more sense to learn procedural programming before any higher level, OO language.
I started with C++, then realized that I don't understand what it does...sure I wrote some Hello World programs, but was not sure how it worked. Then bought KNR, moved on Unix platform and my knowledge began to grow rapidly.
C is the culture.
C++ and others are practical need to write less code faster. More acceptable for bigger applications, programs where efficiency is not that important, easier to understand and maintain....really great languages. And if you don't care about the "black box" and you just want to see the window floating on the desktop or you only care about solving practical problems...C is not the best choice.
There...I hope I made a choice a bit easier.
Mind you, C++ does not sacrifice efficiency. It is even more efficient than C at times. Otherwise you bring up good points.