Thread: Why is C++ used more for software development that C?

  1. #1
    Registered User
    Join Date
    May 2016
    Location
    Behind a computer!
    Posts
    1

    Question Why is C++ used more for software development that C?

    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

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    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?

  3. #3
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Quote Originally Posted by Elkvis View Post
    ... I can foresee large portions of the Linux kernel someday being converted to C++, once Linus is no longer in control. ...
    I do not! The kernel needs to operate as efficiently as possible. There is too much overhead with C++ for "large portions of the Linux kernel" to be rewritten in C++.

    I would love to see/hear Linus's opinion on this! ;^)

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by rstanley View Post
    I would love to see/hear Linus's opinion on this! ;^)
    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.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by rstanley View Post
    There is too much overhead with C++ for "large portions of the Linux kernel" to be rewritten in C++.
    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?

  6. #6
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    @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: ..."

  7. #7
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by rstanley View Post
    @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.

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    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?

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by rstanley View Post
    I would love to see/hear Linus's opinion on this! ;^)
    Linus does not understand C++, nor does he care to. He is completely unqualified to comment on its suitability for use in any application.
    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?

  10. #10
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    More practical, bigger standard library, more useful. Everything C can do + more.

  11. #11
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    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.

  12. #12
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I would love to see/hear Linus's opinion on this!
    O_o

    Foaming steeped in hyperbole followed by a solitary middle finger...

    Except C doesn't have templates. I'm giving C one cookie for that.

    But... macros. I'm taking that cookie back.
    A language with no mechanism for generics beyond abused objects is no language I'd want to use.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  13. #13
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by phantomotap View Post
    A language with no mechanism for generics beyond abused objects is no language I'd want to use.
    Besides standard containers, there's little need for generic types.

  14. #14
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    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.

  15. #15
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by MutantJohn View Post
    Whoa, guys. What's up with the hate for generics?
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Software Development Book?
    By DecoratorFawn82 in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2013, 09:17 PM
  2. Own application development with a software
    By Buster in forum C# Programming
    Replies: 1
    Last Post: 06-25-2012, 07:15 AM
  3. Software Development ideas!!
    By gaurav_13191 in forum Tech Board
    Replies: 2
    Last Post: 01-29-2011, 11:19 AM

Tags for this Thread