LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Guru = C & Lame = C++ (https://www.linuxquestions.org/questions/programming-9/guru-%3D-c-and-lame-%3D-c-148260/)

gr33ndata 02-19-2004 09:56 PM

Guru = C & Lame = C++
 
Hi

Thi may seem to be a silly question, but I am thinking about if since a while
I have been wondering why all - most of - the programmes written on *nix are written in C not C++
Also linux gurus do not mension C++, Classes, new, delete etc. and insted use handlers (alternative to classes somehow) etc.
So what is so special about C and not in C++ ??

KptnKrill 02-19-2004 10:02 PM

I am in no means qualified to answer this question but perhaps it's because unix was originally written in c, and most programs don't *need* oo. ?
Just a guess :)

edit: spelling

PSIplus 02-20-2004 03:06 AM

Hmmm... What do you know about C, C++ or ObjC? Use the program lang YOU like!
And: There are many C++ apps for UNIX Environment (For example the KDE Project!)

The most significant difference between both is the different programming-style... For newbes, both look like the same, but for pros each language contains it special abilities!

Have Fun
Martin

moeminhtun 02-20-2004 03:14 AM

You know why Linux kernel is written in C?
Because that time "Linus" was still a kid (20 something) and he didn't know how to program in C++ yet.

andzerger 02-20-2004 03:58 AM

heh i got blacklisted at college for pestering one of my instructors about how C and C++ had so much in common (loops, data, pre. proc., structs) .. he kept saying "but C++ has classes, its object oriented" well.. i think many CS students (especially at that school) can go a whole 4 years without being taught exactly what the point of object oriented programming is .. im sure I dont know ..
will someone please take a shot at explaining it to me .. ?

codedv 02-20-2004 04:42 AM

I'm not sure this is right and it probably isn't, but the way I understand it OOP gives you away of modeling and structuring your code in a way that represents the real world problem you are trying to solve.

For example you may want to write a program which will be embedded into a kettle microchip. In C++ you may choose to have a kettle object. The kettle object will have a set of things it can do - like boil and stop boiling. It should also be able to communicate its state - e.g temperature of the water and whether or not its on or off.

From your point of view what goes on inside the kettle is of no relevance to you. All you need to to is fill it with water and have the ability to turn it on to boil the water and also be able to see when the kettle has boiled.

So the kettle is an object which encapsulates some code. The object has a user interface, such as a switch and the exact workings of the kettle are hidden in the casing and should never have to be changed.

I hope I havn't completely confused you.:rolleyes:

andzerger 02-20-2004 05:41 AM

thats not confusing, except that it sounds so easy that i doubt my sanity ;)

codedv 02-20-2004 05:52 AM

That's the problem with OOP - it just confues the hell out of me. I understand the concepts but find it a lot easier to use the old fashioned modular approach.

andzerger 02-20-2004 06:37 AM

if youv compiled a program that uses 'cin>>' and cout<< .. have you also compiled all the code required for 'cout<<setw(9)<<' ??

PSIplus 02-20-2004 07:21 AM

Quote:

Originally posted by moeminhtun
You know why Linux kernel is written in C?
Because that time "Linus" was still a kid (20 something) and he didn't know how to program in C++ yet.

The Kernel is coded in C, because it makes sense in this low level! If you want to code low-level code, C++ makes no sense (Think about it - NeXT created Objective-C to do objective things in low levels, C++ itself is not for these purposes)

C++ is good for large Applications - classes and namespaces are very usefull for object-based applications (like KDE or others) - The GTK-based programming can be very complicated, because you need the GObject-Model and other memory sharing/protection and so on...

Have Fun!
Martin

moeminhtun 02-20-2004 07:39 AM

Quote:

Originally posted by PSIplus
The Kernel is coded in C, because it makes sense in this low level! If you want to code low-level code, C++ makes no sense (Think about it - NeXT created Objective-C to do objective things in low levels, C++ itself is not for these purposes)

C++ is good for large Applications - classes and namespaces are very usefull for object-based applications (like KDE or others) - The GTK-based programming can be very complicated, because you need the GObject-Model and other memory sharing/protection and so on...

Have Fun!
Martin

The kernel can be written in C++ and it would turn out to be a very very good designed and fool-proof kernel. For example, have you heard about "symbian" OS? The OS used by high end mobile phones like, nokia 3650, 7250, etc.. The symbian OS is 100% written in C++ and everybody who program on that platform before will have to admin that the OS is very very well-designed, and extremely stable.

jtshaw 02-20-2004 08:33 AM

As I have stated before on C vs. C++ threads.... Back in 1991 the C++ support in GCC was pretty primative (compared to now anyway). That fact, and the fact that C was created specifically to build the UNIX operating system were probably the compeling reasons that Linux was built in C and not C++.

C++ certainly could be used for writing a complete OS kernel. But it certainly wasn't made for that (C++ was designed for higher level applications) and the choice of language has nothing to do with the design or stability of the software. I assure you C as a language is just as stable (and way more mature) then C++.

sNicker 02-20-2004 08:34 AM

Oh well, C and C++ share a very similar sintax but are completely different languages and refer to totally different programming models. There's no point on which is better. A lot of good applications are made in C, a lot of good applications are made in C++. A HUGE amount of bad applications are made in C and in C++ as well.

They are both powerful and quick. If you need low level programming maybe you will choose C, for high-level programming (say GUIs or modular systems) you will choose C++.

I repeat, if you are a good programmer you will be able to take the best from both, and use the right language based on your needs.

C vs C++ it's a silly problem... :)

PSIplus 02-20-2004 10:06 AM

Quote:

Originally posted by moeminhtun
The kernel can be written in C++ and it would turn out to be a very very good designed and fool-proof kernel. For example, have you heard about "symbian" OS? The OS used by high end mobile phones like, nokia 3650, 7250, etc.. The symbian OS is 100% written in C++ and everybody who program on that platform before will have to admin that the OS is very very well-designed, and extremely stable.
Can be written... But what would it cause? It makes sense in some case, but there is neary nothing wich requires C++! It would cause many problems: mutexes and classes, first level memory protection, object registration. Yeah, module-handling would be much easyer and the structures would become much more clean. And it would make preemptivity much more complicated!

But: Linux is a UNIX-Like operating system, using C++ coding it would require new abstracts with syscalls - they have to be exported in C-Style (not really a problem, but it would cause many-many incompatiblities since, if i'm not wrong, any existing POSIX-Like OS is coded in C or ObjC ... Even MSWin is, except of parts of the GDI, coded in C!)

Symbian is not a UNIX-Like multi-purpose operating system, Symbian is an Embedded OS! It was designed to be coded in C++, it is structured for it and it is implemented in C++ (but as far as I know with many parts in C-Style code...)... You cann't compare Linux with Symbian, it's totally different.

chewysplace 02-20-2004 10:53 AM

PSIplus:

the code only sucks as bad as teh coder can program. language realy doesnt matter.


All times are GMT -5. The time now is 05:42 AM.