LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Applications seem favor C over C++, why? (https://www.linuxquestions.org/questions/programming-9/applications-seem-favor-c-over-c-why-132919/)

fr0zen 01-08-2004 09:04 PM

Applications seem favor C over C++, why?
 
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...?

Thanks.

h/w 01-08-2004 09:22 PM

i think one of the main reasons is "using a hammer to go after a fly".

mr_segfault 01-08-2004 09:45 PM

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..

Just my 2 cents...

Cheers.

fr0zen 01-08-2004 10:10 PM

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.

Oh well.

itsme86 01-08-2004 10:36 PM

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

mr_segfault 01-08-2004 10:38 PM

Hey fr0zen, I like your desktop screen shots :)

jtshaw 01-08-2004 10:42 PM

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.

fr0zen 01-09-2004 10:42 AM

Quote:

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?

infamous41md 01-09-2004 11:47 AM

Quote:

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?
not a rock, more like a fly swatter. :)

h/w 01-09-2004 12:04 PM

that's a beautiful screenshot, frozen. sure woke me up.

Strike 01-09-2004 12:25 PM

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.

h/w 01-09-2004 01:00 PM

if you were to write something that does not require obj-oriented design, would you choose C/C++?

jtshaw 01-09-2004 01:38 PM

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.

h/w 01-09-2004 02:29 PM

http://www.artima.com

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.

Mega Man X 01-09-2004 04:29 PM

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)


All times are GMT -5. The time now is 10:24 PM.