Click to See Complete Forum and Search --> : C or C++?? Or does that make sense??
greyhammer
10-05-2003, 07:39 AM
Hello.
From the question, I'm sure anyone reading this realizes that I'm quite a newbie - but only in some ways.
I'm an undergrad, doing physics in the third year, and we've been programming in PASCAL. Running simulations (mostly writing to datafiles and then plotting). Now - well, people at our college have finally seen the sense in using Linux, and so we are!! So at the present moment, I'm caught up in the joys of using GNUPlot, etc. However, I have a question for you people - I'm switiching over to C, because I find, that It's structurally not very different from PASCAL, but I'm not too clear, what's all this hullabaloo about object orientation and C++? As in can I live without it?? And in a while, I'll probably try to do things which use graphics and such things, so what do you people think?? C or C++? I swear I found nothing in the threads about this...
micio
10-06-2003, 08:28 AM
O-O code is more mantainable and suits perfectly when you have many people on the same, big, project. If you have to write few thousands of lines by yourself you can avoid O-O.
Take into account that C++ is not only O-O: it works as a procedural language too (C, Pascal ...) and has templates which are extremely powerful.
I suggest you to start directly with C++ and use it for procedural programming.
Sepero
10-06-2003, 08:58 AM
I would recommend learn C++. Basically it IS C, plus more...
Many people who learn C first, then C++ later tend to carry over bad habits, mainly concerning strings and arrays. Many of them also tend to write procedural code where OO would be much better suited.
Whipping Boy
10-09-2003, 06:11 PM
Also realize that technically, OOP isn't a language construct but a programming paradigm. This means that (theoretically, at least) you can do OOP in any Turing-complete language, such as C. Sure, you won't be able to do things such as polymorphism or inheritance, but the basic concepts can be followed in just about any language.
Hell, I've seen examples of OOP done in Brain****.
bwkaz
10-09-2003, 06:53 PM
Originally posted by Whipping Boy
Sure, you won't be able to do things such as polymorphism or inheritance, Have you looked at Gtk by any chance?
It does both polymorphism and inheritance in C, though it's a bit odd at first.
Basically, the polymorphism happens when a derived gclass takes the struct holding its parent's gclass function addresses, and changes one of them. The derived gclass has an instance of the parent gclass as its first member, so that's how the inheritance part works.
(In Gtk, a "class" is merely a struct containing a bunch of function pointers. It's a lot like VFS in the kernel, actually.)
greyhammer
10-09-2003, 07:55 PM
Hmm....
No, I haven't looked at Gtk - not yet....See, I know Pascal fairly well, and I know that there's a GNU Pascal available, but somehow, I don't quite want to go that way even though I hear it's O-O because it'll be hard to find any books on it. Yes, yes, in this day and age, there are probably online howtos on getting a hold of the language, but a good books's a good book!
Well, we did do some C++ way back in school, but we only glossed over objects and inheritance - it was Borland C++.....infact, if you try and use the header file as <iostream.h> then g++ gives you a message about deprecated header files that will not be supported in a short while...I was quite surprised when I found that "cout" wasn't identified as a function by the compiler in the begining!!
So in fact, I never knew C - I knew some very basic C++, and have been reading up on C of late - things such as operator overloading, function polymorphism, etc. I had found quite attractive in C++, and I miss these in C.
Trogdor
10-09-2003, 08:12 PM
If you are doing normal programs, learn C++. If you are doing low level programs, like operating systems or like, learn C. C++ is downwards compatible with C.
bwkaz
10-09-2003, 10:02 PM
Originally posted by greyhammer
No, I haven't looked at Gtk - not yet... Umm, I was talking to Whipping Boy, actually. :)
Should have been more obvious, sorry about that.
Stuka
10-10-2003, 09:50 AM
Originally posted by greyhammer
infact, if you try and use the header file as <iostream.h> then g++ gives you a message about deprecated header files that will not be supported in a short while There's a good reason for that - iostream.h IS deprecated by the ISO/ANSI C++ Standard (use iostream instead). I was quite surprised when I found that "cout" wasn't identified as a function by the compiler in the begining!! cout is not now, nor has it ever been, a function. cout is an object of class ostream that has as its 'target' stdout (which is, of course, the terminal by default). Search this forum for 'namespace std;' and you'll find plenty of discussions about WHY this is so.
</soapbox>
Whipping Boy
10-10-2003, 10:22 AM
Originally posted by bwkaz
Have you looked at Gtk by any chance?
Not to any significant degree, no.