View Full Version : C vs C++
SonnHalter
February 12th, 2009, 07:55 PM
Well, I'm learning programming VERY SOON, in about a few hours actually. But i have two paths to learn from C & C++ or only C++
I'm inevitably learning C++ for my computer programming class next school year. But a lot of OSs are written in C but a lot of apps are written in C++. I'm really kind of lost
so C vs C++
what is easier for the programmer?
What will benefit linux more?
Is it easy to learn both and distinguish between them?
what don't you like about the other language?
OutOfReach
February 12th, 2009, 08:10 PM
I don't know C++, but I have seen C++ code.
I am currently finishing up learning C, and it is pretty easy and yes it is closely tied in with the Linux kernel. Who says there aren't apps out there written in C?
I believe once you learn C that learning C++ will be easier, it's basically the same with a bit of OOP thrown in.
kavon89
February 12th, 2009, 08:13 PM
All C code should end up also being valid C++ code.
Neither really "benefits" Linux in any way. One might say C++ is easier for a programmer because it is an object oriented language, but I'm willing to bet there are arguments against OOP.
ssam
February 12th, 2009, 08:26 PM
C and C++ are very similar (so are all languages). having learnt one its far less work to learn another. I started learning with BBC basic, and it was a huge head start in learning other languages.
so learn anything to get you started, then when you want to work on a particular project you can learn that language if its different.
kendallcschm
February 12th, 2009, 08:30 PM
i got another question i want to add to this... i have learned windows batch.... what would be the best beginner programming language?? i know a bit of HTML too.. :lolflag:
Mohamedzv2
February 12th, 2009, 08:55 PM
C++ would be better to learn and it was easier for me to learn imo.
Kend:Try learning BASIC, then go to more advanced languages
RiceMonster
February 12th, 2009, 09:05 PM
I did C before I did C++
Learn them both; it's two different ways of programming. C is functional and C++ is object oriented.
i got another question i want to add to this... i have learned windows batch.... what would be the best beginner programming language?? i know a bit of HTML too.. :lolflag:
IMO HTML doesn't count because it's just a markup language. You don't learn any programming logic. Try starting with something simple like Python.
kevdog
February 12th, 2009, 10:21 PM
I suggest C first, however that's just my 2 cents. In some case OOP is not all its cracked up to be. In some instances you can do things just plain more efficient in C.
Polygon
February 13th, 2009, 12:30 AM
if you really get into programming you will most likely end up learning both anyway.
sujoy
February 13th, 2009, 01:33 AM
starting with C++ would complicate things unnecessarily, unless you are familiar with programming already. since most books on C++ tend to force the OOP early on, i would say spend a couple of months on C, read some codes and most importantly learn data structures and algorithms.
phrostbyte
February 13th, 2009, 02:31 AM
C is easier to understand for newbies IMO. C++ is just C with extra stuff tacked on pretty much - more to learn. So you can learn C and then move to C++.
Python is better then both however, since it abstracts away memory management and data types and lets you focus on core logic, so it's very easy to learn how to program in Python.
maxideci
February 13th, 2009, 02:43 AM
at first I learned C and for long, I was not willing to learn C++, but 3 summers ago, it all changed and since then there is no looking back. C is very functional, and C++ is obect oriented.
If you want to manage a large project then C++ is a way to go....
Happy Programming.
Cheers,
steeleyuk
February 13th, 2009, 03:20 AM
C is easier to understand for newbies IMO. C++ is just C with extra stuff tacked on pretty much - more to learn. So you can learn C and then move to C++.
Python is better then both however, since it abstracts away memory management and data types and lets you focus on core logic, so it's very easy to learn how to program in Python.
I'm learning Python at the moment, its a joy to learn to be honest, very easy to throw things together in a short amount of time.
I might consider giving C a go though at some point. I have a bit of a background in programming in Pascal (forced us at college, it wasn't by choice) and C appears to be quite close to Pascal...
Eisenwinter
February 13th, 2009, 03:41 AM
I suggest also learning Perl, it's a wonderful language, and will broaden up the way you think about programming.
lakersforce
February 13th, 2009, 03:47 AM
Python is better then both however, since it abstracts away memory management and data types and lets you focus on core logic, so it's very easy to learn how to program in Python.
But that's where all the fun starts!!
Eisenwinter
February 13th, 2009, 03:55 AM
But that's where all the fun starts!!
I guess it also provides good programming habits, such as checking your program in-depth, and in a way also "force" you to write cleaner code, if your code is intended to be read by others.
gnomeuser
February 13th, 2009, 04:00 AM
If you must, C++, the designs and way of thinking you learn from Object Oriented programming will translate easily into other languages.
Learning how to program is definitely more important than the language you do it in. I personally learned C++ and Intel x86 ASM in college, but neither are really pleasant to work with IMHO. I do like C# though.
ego-sum-deus
February 13th, 2009, 04:04 AM
i agree with a lot of posters here that C is easier to understand for a new programmer, but there is no need to learn it first. any c++ programmer will tell you that this is not a necessity to learning c++.
as for my experience, i started programming in FORTRAN doing heavy numerical computation. last year i picked up a c++ book and started working through it and it is a great language (a lot of physics code is being transferred from fortran to c++ nowadays). i saw no real need to learn C first, so i skipped it all together. but at the end of the day, you will inevitably learn both as time goes on. one thing i will tell you though is that in my case, i have a huge bias towards my first language (fortran). i think many programmers will tell you this is also...that they have a deep affection with that first language that they learn lol wow, we are dorks!!!! hahaha just kidding of course.
you also asked for other languages that are beneficial...i think it comes down to what you are programming for. if you are doing a lot of scientific computations, fortran, c++, and even python are the way to go. i cannot speak very deeply for other programming tasks except for linux. with linux, the kernel and base software like vi, emacs, cd and rm commands are written in C. but A LOT of stuff is also done in python, perl, and java.
howlingmadhowie
February 13th, 2009, 04:37 AM
just so you know, C is just as object-oriented as C++ (apart from inheritance which you really shouldn't be using anyway).
in general C++ is a terribly broken language and i would stay well away. if you want to use something 'object-oriented' either stay in C and use structs with function pointers in them, or move to a modern interpreted language such as python, ruby or smalltalk.
in my not so humble opinion, every programmer should be fluent in C. it teaches you so much about the hardware and the operating system, about how computers work. C++ tried to fix parts of C which weren't broken and ended up breaking a whole lot more.
here a rant about C++: clickity (http://groups.google.com/group/comp.lang.lisp/msg/917737b7cc8510e3?pli=1), a more humorous take here (http://www.phy.duke.edu/~rgb/Beowulf/c++_interview/c++_interview.html), and of course here (http://lwn.net/Articles/249460/). if you're a beginner programmer, you probably won't understand a word of it, which is why C++ has been so successful. the beginner sees an object oriented version of C that is also backwards compatible. the experienced programmer sees a godless mess.
koenn
February 13th, 2009, 04:43 AM
I believe once you learn C that learning C++ will be easier, it's basically the same with a bit of OOP thrown in.
there's a fundamental difference between object oriented programming and functional programming so you can't just claim C++ is C with OPP thrown in. You don't just 'tack on some OOP', it's a completely different approach/perspective/paradigm/....
That said, apart from being object oriented, C++ is, by design, also backwards compatible with C so you can (more or less) "write C" in C++. There's a huge overlap in vocabulary and syntax between the two.
koenn
February 13th, 2009, 04:49 AM
just so you know, C is just as object-oriented as C++ (apart from inheritance which you really shouldn't be using anyway).
You've just opened the door to a yet another episode in the eternal programming language wars, and I don't really want to go there, but nonetheless:
- just how is C object oriented ?
- what's the point of object orientation if you're not going to have inheritance ?
- why shouldn't you use inheritance anyway ?
howlingmadhowie
February 13th, 2009, 05:08 AM
You've just opened the door to a yet another episode in the eternal programming language wars, and I don't really want to go there, but nonetheless:
- just how is C object oriented ?
- what's the point of object orientation if you're not going to have inheritance ?
- why shouldn't you use inheritance anyway ?
C is object oriented because you can use an object oriented paradigm through structs.
with inheritance, the behavior of subclasses can depend on the private behavior of superclasses. this leads to great difficulties when overriding methods. the only safe way of implementing inheritance is not to use it but to create an instance of the class you want to inherit from in the class which is to act as the subclass. and you can do that just as well in C.
the point of object orientation is more to be found in data encapsulation, which is basically a marketing term for "we can make a project so large and so complex that a thousand programmers will have to write on it at the same time", something management loves to hear. unfortunately, C++ takes this to extremes. things like changing the type a private member variable in a class means you have to recompile all files which include this class. at least java gets that right.
-----
edit
btw, the technique i mention above is called composition. it can be a good idea, provided you declare everything to be public (which you should do nowadays anyway). otherwise it can get extremely wordy and contribute to code bloat.
sujoy
February 13th, 2009, 05:58 AM
and some advice from masters in the field, http://catb.org/~esr/faqs/hacker-howto.html#skills1
it might seem that the ubuntuforums has a bunch of python fanboys, however, its not. python is really one of the languages that helps a beginner grasp the concepts of programming rather than having to dabble around in syntax, memory and what not.
however, keep this in mind that you really need to learn a few languages (more than 2 atleast) so that you have the right tool to apply at the right project. so start with python, if you are a completely new to programming, else suit yourself with C or anything else that you prefer (hopefully not C++, see howlingmadhowie's post, so i need not repeat it)
bruce89
February 13th, 2009, 06:31 AM
just so you know, C is just as object-oriented as C++ (apart from inheritance which you really shouldn't be using anyway).
in general C++ is a terribly broken language and i would stay well away. if you want to use something 'object-oriented' either stay in C and use structs with function pointers in them, or move to a modern interpreted language such as python, ruby or smalltalk.
Enter GObject (http://library.gnome.org/devel/gobject/stable/), C object library.
bryonak
February 13th, 2009, 11:31 AM
there's a fundamental difference between object oriented programming and functional programming so you can't just claim C++ is C with OPP thrown in. You don't just 'tack on some OOP', it's a completely different approach/perspective/paradigm/....
That said, apart from being object oriented, C++ is, by design, also backwards compatible with C so you can (more or less) "write C" in C++. There's a huge overlap in vocabulary and syntax between the two.
You are right about that you shouldn't just 'tack on some OOP', but unfortunately this is exactly what C++ does.
It is a nice, efficient language and the prime choice for various tasks, but the OOP part of C++ is broken and 'tacked on' compared to all other OOP languages out there. It is really just a very messy try to bring OOP to C.
I'm a bit lazy about the sources now, but try searching for programming mailing lists or forums via Google (there's also those links howlingmadhowie posted)... it's the general opinion among many coders.
Oh, and maybe I should slip in a disclaimer that I'm a C coder ;)
On topic:
C is 'nearer' to the hardware, which means it lets... err... makes you learn more about a programming approach that honors how the computer works internally. C++ is more abstract because of it's OOP and will teach you generic programming logic from a 'end user programmer's point of view', not the computer's one.
Then again, my opinion is that Python does a muchg better job of this***. As does Java, Ruby, nameityourself... because their OOP can be taken seriously ;)
This is not to say that C doesn't do this as well.. it's just that you won't get there as quickly (compared to the mentioned more abstract languages) because of all the other things you have to learn first.
Which I think are very important for every programmer.
Bottom line: learn C first, you will get lots of frustration and valuable insights. Then enjoy the ability to easily learn any more abstract language.
*** I'm not pushing for Python here, since my Python skills aren't really great. But the point stands.
forrestcupp
February 13th, 2009, 11:51 AM
there's a fundamental difference between object oriented programming and functional programming so you can't just claim C++ is C with OPP thrown in. You don't just 'tack on some OOP', it's a completely different approach/perspective/paradigm/....
That said, apart from being object oriented, C++ is, by design, also backwards compatible with C so you can (more or less) "write C" in C++. There's a huge overlap in vocabulary and syntax between the two.
I think the point was probably that the syntax is a lot alike, but C++ has an OPP approach thrown in.
koenn
February 13th, 2009, 12:00 PM
You are right about that you shouldn't just 'tack on some OOP', but unfortunately this is exactly what C++ does. ... It is really just a very messy try to bring OOP to C.
err... not really.
Tacking on OO would be more like what howlingmadhowie proposes, mimimicking OO behaviour with structs and pointers to functions, or like what VB 6 did: implementing a little bit of OO with class modules, etc.
C++ is an OO language first, it's the compatibility with C that was 'tacked on', and that was probably the biggest mistake. Java did not make that mistake. Another mistake was probably that C++ wants to be everything. It has OO features to the extreme, inluding multiple inheritance and overriding and overloading polymorphism, support for template programming and what not, alongside the more traditional procedural programming and the already mentioned compatibility with C.
On topic:
C is 'nearer' to the hardware, which means it lets... err... makes you learn more about a programming approach that honors how the computer works internally. C++ is more abstract because of it's OOP and will teach you generic programming logic from a 'end user programmer's point of view', not the computer's one.
Well, it kinda depends what you want then : do you learn programming to get better insight on how a computer works, or do you want to know programming to be able to solve real life problems, i.e. create programs that help to store and manage information, automate processes, facilitate communication, ...
forrestcupp
February 13th, 2009, 12:01 PM
C is object oriented because you can use an object oriented paradigm through structs.Structs are very useful, but they aren't nearly as powerful as a class.
with inheritance, the behavior of subclasses can depend on the private behavior of superclasses. this leads to great difficulties when overriding methods. the only safe way of implementing inheritance is not to use it but to create an instance of the class you want to inherit from in the class which is to act as the subclass. and you can do that just as well in C.
The things you're saying are definitely true if you don't mind always programming from the ground up. But for those who go by the philosophy "don't reinvent the wheel", sometimes inheritance is very useful and time saving, especially if you're programming with a framework or engine. In that case, it's usually necessary.
And about the original post, both C and C++ can be helpful in Linux or any other OS. You just need to decide where your interests lie. Are you wanting to do low level stuff? Go with C. Are you wanting to program apps? If so, figure out which framework/engine you want to program with (GTK, wxWidgets, SDL, Ogre3D, etc.) and find out whether it uses C or C++. Most of these use C++. GTK uses C, but it has bindings for C++ and many others. Win32 for Windows uses C.
If you learn C++, you won't have any problem learning the things that require C.
bapoumba
February 13th, 2009, 04:58 PM
Moved to Recurring Discussions.
howlingmadhowie
February 13th, 2009, 11:07 PM
Structs are very useful, but they aren't nearly as powerful as a class.
just out of interest, any concrete examples?
The things you're saying are definitely true if you don't mind always programming from the ground up. But for those who go by the philosophy "don't reinvent the wheel", sometimes inheritance is very useful and time saving, especially if you're programming with a framework or engine. In that case, it's usually necessary.
i agree with you that there are cases where inheritance is probably the right solution. my point is that you generally don't want to use it in cases where code is likely to be changed, because you may end up breaking stuff. inheriting interfaces is of course something totally different and a good solution to problems with static typing.
inheritance is only necessary in languages that think static typing is better than duck typing. static typing is however fairly pointless for object oriented code if you allow inheritance and don't have a runtime environment that can find miscasts---the ClassCastException in java. That C++ does not and cannot support this (while having templates!?!) is a real problem.
of course, with duck typing you don't have this problem and you can leave behind the safety net (and annoying verbosity) of static typing.
If you learn C++, you won't have any problem learning the things that require C.
i'm not sure this is always true. there are many things is C++ that are encouraged and are bad programming practice. an example would be operator overloading. one can define '+' to mean anything you want it to. if this token now appears in some file with 10 different imports for 10 different classes, you can have a lot of fun trying to work out what it does. it may be a bad example of what i mean. basically, C++ encourages one programming style while C encourages a different one. Learning to write good C code after having learnt C++ could be difficult. I don't know. I learnt C first.
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.