Hi everyone,
I am new to programming and I have started to learn C and I love it!
However the main question I have is why is C++ used more than C for software development (making applications).
Sorry if this is a stupid question.
Thanks
Hi everyone,
I am new to programming and I have started to learn C and I love it!
However the main question I have is why is C++ used more than C for software development (making applications).
Sorry if this is a stupid question.
Thanks
For typical (desktop) applications, an object-oriented approach is a good fit for GUI programming, so C++ sees a lot of use there. For scientific research, it's much easier to write high-performing code that is also memory safe in C++, so it sees a lot of use there as well. I wouldn't say it is used more than C, but it's certainly a strong competitor to C. I can foresee large portions of the Linux kernel someday being converted to C++, once Linus is no longer in control. Object oriented design works well for operating system concepts as well.
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
As if we didn't have enough of that. He has always been very vocal about C++.
But truth the matter is that Linus isn't the only software engineer out there. And neither is he the only one developing kernels. Many other SEs are perfectly happy writing kernel code in C++ without falling to the repetitive and boring-already nonsense that "C++ is a slow and bulky language". And their kernels work just fine, proving them right.
Now, the only thing that can be said here is that it makes no sense to turn the linux kernel into a C++ kernel because there is no benefit in it that outweighs the massive cost of converting the code. And only that.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
And you base this on what exactly? C++ adheres to the guiding principle that "you don't pay for things you don't use." In a "freestanding environment," as described in the C++ standard, such as an operating system kernel, there is no standard library, streams, containers, etc. I fail to see how there would be any overhead. There is the C++ language, and whatever code the developer decides to add. RAII, for example, would be extremely useful in a kernel environment.
Last edited by Elkvis; 05-25-2016 at 09:23 AM.
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
@Elkvis:
Given what you say, I still see no benefit to switch to C++. GCC which is currently being used to compile the kernel, already "... implements a non-standard extension to the C language to support RAII: ..."
The kernel also has an extensive system for object oriented programming which is somewhat counter intuitive to use.
14.1. Kobjects, Ksets, and Subsystems
This is something that would be trivial with C++.
Also cleaner to use and understand.
And faster, unless you keep on creating a C extensions like "cleanup" from your link, at that point you are no longer using C.
I do not think it is feasible to convert Linux to use C++, but for someone starting to write a new kernel, using C++ will be considerably easier.
As you said, it's nonstandard, and should be avoided in code intended to be portable. Chances are, it's not even used in the Linux kernel, because of its nonstandard-ness. If not the existing kernel code, I can certainly see the door being open to allow official kernel modules, written in C++, so long as they provide a compatible binary interface to the existing kernel.
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
More practical, bigger standard library, more useful. Everything C can do + more.
Except C doesn't have templates. I'm giving C one cookie for that.
But... macros. I'm taking that cookie back.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
O_oI would love to see/hear Linus's opinion on this!
Foaming steeped in hyperbole followed by a solitary middle finger...
A language with no mechanism for generics beyond abused objects is no language I'd want to use.Except C doesn't have templates. I'm giving C one cookie for that.
But... macros. I'm taking that cookie back.
Soma
“Salem Was Wrong!” -- Pedant Necromancer
“Four isn't random!” -- Gibbering Mouther
Whoa, guys. What's up with the hate for generics? Also, this is the wrong time to hate them! There's enable_if and concepts has a formal technical specification, I think. Heck, GCC 6.1 even has an implementation of concepts available.
No hate. Instead, dislike of their language design. Much as I dislike macros (although here it's more to do with developers).
Have you ever looked at a generics tree that tries to be something more than the most basic of structures? Those things are nearly indecipherable. It's syntactic gibberish with real meaning that will take an axe through your skull to finally understand. Templates are the most horrid syntactic addition to C++, making them difficult to learn, difficult to use, difficult to understand and difficult to maintain. I'd rather spend my time reading Mandarin in braille.
EDIT: And because, unless you are a library writter your use case for generics is considerably low, any time you eventually have to use them you will have to actually go back and relearn the whole damn thing, because there is no way you can keep that stuff in your head if you don't use it every day of your life (templates are C++ regex).
Last edited by Mario F.; 05-25-2016 at 08:42 PM.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.