ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've programmed in both C and C++. I don't mind either language, each has its special quirks.
What I don't understand is, if C++ offers the same functionality as C, but in a more OOP manner, why do most developers choose C over C++?
Is it because they don't understand OOP? Choose not to use it? Old code, and porting would take too long? Pointless? Or is there something I'm missing...?
Without even taking all the other factors into consideration, in my experience, all non trivial programs use containers of some sort (linked lists, arrays etc) in C this is a pain since there are no standard container (ADT like linked lists) types in the language spec (other than arrays).
And for every C program I have worked on a large portion of the development effort is spent developing ADT (abstract data types)... Now with C++ we have them all at our finger tips..
If you dont like C++ I'd suggest using a C++ compiler even if it is just for the std containers..
Well I do like C++, and C. I was just curious as to why C is favored more. I suppose I do see the logic behind the "using a hammer to go after a fly" analogy, but if that's true, then C++ was a waste of time to develop. If C++ is a hammer, what is C? A rock?
Most of what I code uses C++, mostly because of the STD containers. I just started noticing (after having had to make changes in source files for several applications) that not many production level applications appear to make use of them.
I much prefer C over C++. Part of the reason is because the executable is usually a bit bigger for C++ programs. Another reason is uhh...I don't know. I learned C first and there's nothing I can't do in C that C++ would let me do I guess Maybe my brain just doesn't think OOP very well. :P
I am not going to start a discussion on C vs. C++ because that could easily start a holy war. I will say that compilers is the total reason why most things linux are in C.
GCC, the free (as in beer) compiler used for most things linux, started out as a C compiler (GCC used to stand for Gnu C Compiler if I am not mistaken). It's support for C has, and still is, better then it's support for C++. They have messed around with the C++ part of it so much they even broke compatibility going from 3.0 to 3.1. As a result many people utilizing these tools have tended to go toward C because the C compiler is more stable, and more heavily tested over the last 27 years.
The kernel itself is C probably because way back in the 1991 gcc was still mostly just a C compiler and Object Orientation and Abstraction, while logically very efficient, doesn't lend itself to code that is as fast or as memory friendly as function code with only simple data types.
Originally posted by mr_segfault Hey fr0zen, I like your desktop screen shots
Heh. Thanks. :P
Quote:
Originally posted by jtshaw I am not going to start a discussion on C vs. C++ because that could easily start a holy war. I will say that compilers is the total reason why most things linux are in C.
GCC, the free (as in beer) compiler used for most things linux, started out as a C compiler (GCC used to stand for Gnu C Compiler if I am not mistaken). It's support for C has, and still is, better then it's support for C++. They have messed around with the C++ part of it so much they even broke compatibility going from 3.0 to 3.1. As a result many people utilizing these tools have tended to go toward C because the C compiler is more stable, and more heavily tested over the last 27 years.
The kernel itself is C probably because way back in the 1991 gcc was still mostly just a C compiler and Object Orientation and Abstraction, while logically very efficient, doesn't lend itself to code that is as fast or as memory friendly as function code with only simple data types.
I was careful in choosing the wording for my question as I too have no interest in sparking a C & C++ jihad. Your explanation for the reasons behind the usage of C in preference to C++ is sufficient for me. The main reason I like C++ is because I use the STD containers.
Are there any C oriented STD-like containers available?
Originally posted by fr0zen Well I do like C++, and C. I was just curious as to why C is favored more. I suppose I do see the logic behind the "using a hammer to go after a fly" analogy, but if that's true, then C++ was a waste of time to develop. If C++ is a hammer, what is C? A rock?
I'd say the hammer analogy is misguided. If anything, C is the hammer simply because it is a "heavier" tool in that you have to do so much with it, and it can be considered more powerful in that you can do ANYTHING in it that can be done on a machine that it compiles/runs on, basically.
Also, why do you say more people choose C? What kind of apps are we talking about here anyway?
In an ideal world, the language used would reflect the problem's domain. Of course, in this ideal world C would be used only for things that are speed-critical, basically. But, people use C instead of C++ a lot of times because C is just easier to hack together and using C++ requires more design and planning to get it done right. Ideally, many of the "utility" apps that use C++ would be written in a higher level language like Python because it would solve their problems better. Note: by "utility" I don't mean larger-scale apps where response time is critically important.
I would choose C if I was writing someting that didn't require obj-oriented design. But that is probably because I am most comfortable with C and I use it the most out of all the different programming languages.
i think i had seen the hammer-fly analogy there. there are a few nice interviews with stroustrup on the index page itself. excellent read if you don't already know what he's talking about.
I've been programming only in C++ for quite a long time(hobby) now, because it was, and still is, the only choice for courses around here and most of tutorials on the net are about it, and so are the books. I've read huge books about it, I've done a lot of small projects and now we (at the school) are starting out with Java (one month programming with Java now) which is purely OO and guess what? I still cannot see a good reason for using OO... at least not in my applications. A gui program would require more OO, as defining a class Window and buttons and so on... but other then that, I still don't know why or when I'm supposed to use OO. You could tell me that it makes the code more usable, more easy to update it and everything that is on the books I know . I don't understand the concept of OO in "practice". Everything in theory is beautiful though... Any ideas about it? Because I code in C++, using a C style if you know what I mean... (sounds dumb, but I mean C++ syntaxes)
Last edited by Mega Man X; 01-09-2004 at 06:33 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.