Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Makes inheritance C++ slower than C?

Makes inheritance C++ slower than C?

Scheduled Pinned Locked Moved C / C++ / MFC
c++designooptutorialquestion
30 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cyon111
    wrote on last edited by
    #1

    I need some opinions, does make inheritance C++ slower than C and if yes, would it make sense to not use inheritance at all for that reason. I must admit that I'm not getting the idea behind inheritance and therefore would rather like to keep inheritance out of my code! I mean I know how to use inheritance in theory but I always felt it's something programmers don't really need. In short terms, I HATE INHERITANCE. So I'm looking for a good reason(excuse :laugh: ) to keep it out of my code. I'm working on a project right now and so far I'm not using inheritance and I'm happy with that. So in order to have something to write into my Technical Design Document of the Gunman project. I need a few good reasons why I kept inheritance out of my code. This Technical Design Document later will read my future employer, so it's part of my CV and I need something good to write. Everything, but no excuses! :laugh:

    M J C T D 5 Replies Last reply
    0
    • C Cyon111

      I need some opinions, does make inheritance C++ slower than C and if yes, would it make sense to not use inheritance at all for that reason. I must admit that I'm not getting the idea behind inheritance and therefore would rather like to keep inheritance out of my code! I mean I know how to use inheritance in theory but I always felt it's something programmers don't really need. In short terms, I HATE INHERITANCE. So I'm looking for a good reason(excuse :laugh: ) to keep it out of my code. I'm working on a project right now and so far I'm not using inheritance and I'm happy with that. So in order to have something to write into my Technical Design Document of the Gunman project. I need a few good reasons why I kept inheritance out of my code. This Technical Design Document later will read my future employer, so it's part of my CV and I need something good to write. Everything, but no excuses! :laugh:

      J Offline
      J Offline
      Jijo Raj
      wrote on last edited by
      #2

      Cyon111 wrote:

      I need some opinions, does make inheritance C++ slower than C and if yes, would it make sense to not use inheritance at all for that reason.

      Inheritance helps to reuse the existing code with little or no modification. It always improve your performance design and reduce complexity - if used wisely. :rolleyes: I think the term performance made confusion.

      Cyon111 wrote:

      In short terms, I HATE INHERITANCE. So I'm looking for a good reason(excuse Laugh ) to keep it out of my code. I'm working on a project right now and so far I'm not using inheritance and I'm happy with that.

      :omg: I recommend you to go through the object oriented concepts once again. Regards, Jijo.

      _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

      modified on Tuesday, August 26, 2008 5:47 AM

      R 1 Reply Last reply
      0
      • C Cyon111

        I need some opinions, does make inheritance C++ slower than C and if yes, would it make sense to not use inheritance at all for that reason. I must admit that I'm not getting the idea behind inheritance and therefore would rather like to keep inheritance out of my code! I mean I know how to use inheritance in theory but I always felt it's something programmers don't really need. In short terms, I HATE INHERITANCE. So I'm looking for a good reason(excuse :laugh: ) to keep it out of my code. I'm working on a project right now and so far I'm not using inheritance and I'm happy with that. So in order to have something to write into my Technical Design Document of the Gunman project. I need a few good reasons why I kept inheritance out of my code. This Technical Design Document later will read my future employer, so it's part of my CV and I need something good to write. Everything, but no excuses! :laugh:

        M Offline
        M Offline
        Matthew Faithfull
        wrote on last edited by
        #3

        Does inheritance make C++ slower? Assuming you're comparing to C++ used without inheritance then the answer is probably yes a tiny bit in the short term but no in the longer term. Each call to a virtual instruction takes a few ~5 instructions more than a non virtual call but becuase your code will be smaller when written using inheritance, with less copying of data the overall result has a reasonable chance of being faster, less cache misses, faster loading, faster Dll rebasing etc. If you're really keen on speeding up your C++ code you'll get 1000 x as much performance improvement from using an optmised heap manager as you will from avoiding a few virtual calls. As for inheritence, it's there for a reason and that reason is that a lot of very experienced developers think it's good idea and make use of it. Draw your own conclusions :)

        "The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)

        C 1 Reply Last reply
        0
        • C Cyon111

          I need some opinions, does make inheritance C++ slower than C and if yes, would it make sense to not use inheritance at all for that reason. I must admit that I'm not getting the idea behind inheritance and therefore would rather like to keep inheritance out of my code! I mean I know how to use inheritance in theory but I always felt it's something programmers don't really need. In short terms, I HATE INHERITANCE. So I'm looking for a good reason(excuse :laugh: ) to keep it out of my code. I'm working on a project right now and so far I'm not using inheritance and I'm happy with that. So in order to have something to write into my Technical Design Document of the Gunman project. I need a few good reasons why I kept inheritance out of my code. This Technical Design Document later will read my future employer, so it's part of my CV and I need something good to write. Everything, but no excuses! :laugh:

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          Cyon111 wrote:

          This Technical Design Document later will read my future employer, so it's part of my CV and I need something good to write.

          Well, don't put that in your CV because I guess nobody a bit experienced will hire you. Without inheritance, you wouldn't be able to realistically write Object Oriented code. And I can assure you that OO programming is quite used in C++ or any library that you will use. I guess you didn't really understand all the power it can bring to your code. Read some articles about polymorphism, you'll see what it will bring to you.

          Cyon111 wrote:

          but I always felt it's something programmers don't really need.

          I use it all the time, believe me. I can't imagine not using it anymore.

          Cédric Moonen Software developer
          Charting control [v1.5 - Updated] OpenGL game tutorial in C++

          C 1 Reply Last reply
          0
          • M Matthew Faithfull

            Does inheritance make C++ slower? Assuming you're comparing to C++ used without inheritance then the answer is probably yes a tiny bit in the short term but no in the longer term. Each call to a virtual instruction takes a few ~5 instructions more than a non virtual call but becuase your code will be smaller when written using inheritance, with less copying of data the overall result has a reasonable chance of being faster, less cache misses, faster loading, faster Dll rebasing etc. If you're really keen on speeding up your C++ code you'll get 1000 x as much performance improvement from using an optmised heap manager as you will from avoiding a few virtual calls. As for inheritence, it's there for a reason and that reason is that a lot of very experienced developers think it's good idea and make use of it. Draw your own conclusions :)

            "The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)

            C Offline
            C Offline
            Cyon111
            wrote on last edited by
            #5

            I was afraid of that. A lot of very experienced developers you say? Well, whether I want it to or not I think as soonest I have time available, I have to run some tests on inheritance. I mean, if I try to play the smart ass and say that inheritance is for nothing but the truth is the opposite, what would my future employer think? NOOOOOB! :sigh: That would be bad!

            C M 2 Replies Last reply
            0
            • C Cyon111

              I need some opinions, does make inheritance C++ slower than C and if yes, would it make sense to not use inheritance at all for that reason. I must admit that I'm not getting the idea behind inheritance and therefore would rather like to keep inheritance out of my code! I mean I know how to use inheritance in theory but I always felt it's something programmers don't really need. In short terms, I HATE INHERITANCE. So I'm looking for a good reason(excuse :laugh: ) to keep it out of my code. I'm working on a project right now and so far I'm not using inheritance and I'm happy with that. So in order to have something to write into my Technical Design Document of the Gunman project. I need a few good reasons why I kept inheritance out of my code. This Technical Design Document later will read my future employer, so it's part of my CV and I need something good to write. Everything, but no excuses! :laugh:

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              If inheritence was useless, why would people invent new languages such like Java or C# which are fully OO ? man, you certainly have to go through OOP and forget your way of thinking in C.

              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              C 1 Reply Last reply
              0
              • C Cyon111

                I was afraid of that. A lot of very experienced developers you say? Well, whether I want it to or not I think as soonest I have time available, I have to run some tests on inheritance. I mean, if I try to play the smart ass and say that inheritance is for nothing but the truth is the opposite, what would my future employer think? NOOOOOB! :sigh: That would be bad!

                C Offline
                C Offline
                Cedric Moonen
                wrote on last edited by
                #7

                I think you are only looking at one side of the problem. Everything is not only about performances. Otherwise, why not write everything in assembler ? That's certainly in theory the most performant choice. In theory only because of course you loose a lot of features that help you write maintainable code, so you will probably introduce more bugs. I know what you think about it because I had the same point of view when I learned that at school. I also thought that virtual functions were totally useless. Man, was I ever so wrong :-D . I think you need to play a lot with it to see that it can make your code much more readable. But you have to switch to the OO way of thinking which is quite difficult at the begining. Otherwise, why using C++ if you are merely doing C using the C++ syntax ?

                Cédric Moonen Software developer
                Charting control [v1.5 - Updated] OpenGL game tutorial in C++

                1 Reply Last reply
                0
                • C Cedric Moonen

                  Cyon111 wrote:

                  This Technical Design Document later will read my future employer, so it's part of my CV and I need something good to write.

                  Well, don't put that in your CV because I guess nobody a bit experienced will hire you. Without inheritance, you wouldn't be able to realistically write Object Oriented code. And I can assure you that OO programming is quite used in C++ or any library that you will use. I guess you didn't really understand all the power it can bring to your code. Read some articles about polymorphism, you'll see what it will bring to you.

                  Cyon111 wrote:

                  but I always felt it's something programmers don't really need.

                  I use it all the time, believe me. I can't imagine not using it anymore.

                  Cédric Moonen Software developer
                  Charting control [v1.5 - Updated] OpenGL game tutorial in C++

                  C Offline
                  C Offline
                  Cyon111
                  wrote on last edited by
                  #8

                  Cedric Moonen wrote:

                  Well, don't put that in your CV because I guess nobody a bit experienced will hire you.

                  Yes, to this conclusion I came with the last reply of mine, too. :rose: Hell it was a good idea to post here before I put it seriously into my TDD and not to mention into the CV. :omg:

                  1 Reply Last reply
                  0
                  • J Jijo Raj

                    Cyon111 wrote:

                    I need some opinions, does make inheritance C++ slower than C and if yes, would it make sense to not use inheritance at all for that reason.

                    Inheritance helps to reuse the existing code with little or no modification. It always improve your performance design and reduce complexity - if used wisely. :rolleyes: I think the term performance made confusion.

                    Cyon111 wrote:

                    In short terms, I HATE INHERITANCE. So I'm looking for a good reason(excuse Laugh ) to keep it out of my code. I'm working on a project right now and so far I'm not using inheritance and I'm happy with that.

                    :omg: I recommend you to go through the object oriented concepts once again. Regards, Jijo.

                    _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

                    modified on Tuesday, August 26, 2008 5:47 AM

                    R Offline
                    R Offline
                    Rajesh R Subramanian
                    wrote on last edited by
                    #9

                    Funny how you got downvoted on that. :)

                    Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

                    J 1 Reply Last reply
                    0
                    • C Cyon111

                      I was afraid of that. A lot of very experienced developers you say? Well, whether I want it to or not I think as soonest I have time available, I have to run some tests on inheritance. I mean, if I try to play the smart ass and say that inheritance is for nothing but the truth is the opposite, what would my future employer think? NOOOOOB! :sigh: That would be bad!

                      M Offline
                      M Offline
                      Matthew Faithfull
                      wrote on last edited by
                      #10

                      Exactly. Of course as Cedric says it's not al about performance. There's also all the cool things you can do with inheritance that you could of course do without it but it wouldn't be any fun. Here's my map class for example //-------------------------------------------------------------------------------- template < class TFirst, class TSecond > class CTMap : public CTIndexedArray < CTMapPair < TFirst, TSecond > > { public: typedef CTMapPair<TFirst, TSecond> TItem; CTMap() { } virtual ~CTMap() { } bool operator != (CTMap<TFirst, TSecond>& Comperand) { return ! CTIndexedArray< TItem >::operator ==(Comperand); } }; Yep, that's all of it. So small I can post it here thanks to inheritance. :-D

                      "The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)

                      1 Reply Last reply
                      0
                      • T toxcct

                        If inheritence was useless, why would people invent new languages such like Java or C# which are fully OO ? man, you certainly have to go through OOP and forget your way of thinking in C.

                        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                        C Offline
                        C Offline
                        Cyon111
                        wrote on last edited by
                        #11

                        Yes, I guess I stick to C pretty much. My slogan was: "Simple but effective!". With inheritance now I'm not sure whether I can maintain this slogan any more. Though, if it's true that inheritance can improve the design of the code, and I'm beginning to understand that it can, then for the sake of my slogan indeed I HAVE to include inheritance into my code.

                        R T 2 Replies Last reply
                        0
                        • C Cyon111

                          Yes, I guess I stick to C pretty much. My slogan was: "Simple but effective!". With inheritance now I'm not sure whether I can maintain this slogan any more. Though, if it's true that inheritance can improve the design of the code, and I'm beginning to understand that it can, then for the sake of my slogan indeed I HAVE to include inheritance into my code.

                          R Offline
                          R Offline
                          Rajesh R Subramanian
                          wrote on last edited by
                          #12

                          Cyon111 wrote:

                          Yes, I guess I stick to C pretty much. My slogan was: "Simple but effective!".

                          :omg: :wtf: Simple? You must try working on large code bases, one written on C and another on C++. You will then know which is more simpler.

                          Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

                          C 1 Reply Last reply
                          0
                          • C Cyon111

                            Yes, I guess I stick to C pretty much. My slogan was: "Simple but effective!". With inheritance now I'm not sure whether I can maintain this slogan any more. Though, if it's true that inheritance can improve the design of the code, and I'm beginning to understand that it can, then for the sake of my slogan indeed I HAVE to include inheritance into my code.

                            T Offline
                            T Offline
                            toxcct
                            wrote on last edited by
                            #13

                            Cyon111 wrote:

                            Simple but effective

                            maybe. now with C++, your slogan will become "Effective at any cost !" :cool:

                            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                            R 1 Reply Last reply
                            0
                            • R Rajesh R Subramanian

                              Funny how you got downvoted on that. :)

                              Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

                              J Offline
                              J Offline
                              Jijo Raj
                              wrote on last edited by
                              #14

                              Rajesh R Subramanian wrote:

                              Funny how you got downvoted on that. Smile

                              No idea buddy. Well, now a days I try to follow CPillani. He's so cool to down votes. He really never minds it. :D Regards, Jijo.

                              _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

                              1 Reply Last reply
                              0
                              • R Rajesh R Subramanian

                                Cyon111 wrote:

                                Yes, I guess I stick to C pretty much. My slogan was: "Simple but effective!".

                                :omg: :wtf: Simple? You must try working on large code bases, one written on C and another on C++. You will then know which is more simpler.

                                Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

                                C Offline
                                C Offline
                                Cyon111
                                wrote on last edited by
                                #15

                                Well, there was a misconception on my side. I always thought that a simple language will resolve in a simple, short code. I might be wrong about that. :doh:

                                T 1 Reply Last reply
                                0
                                • C Cyon111

                                  Well, there was a misconception on my side. I always thought that a simple language will resolve in a simple, short code. I might be wrong about that. :doh:

                                  T Offline
                                  T Offline
                                  toxcct
                                  wrote on last edited by
                                  #16

                                  well, let's imagine the smarter/most effective language in the world. how many lines of code de you think it would be for Windows to be written ?

                                  [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                                  R C 2 Replies Last reply
                                  0
                                  • T toxcct

                                    Cyon111 wrote:

                                    Simple but effective

                                    maybe. now with C++, your slogan will become "Effective at any cost !" :cool:

                                    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                                    R Offline
                                    R Offline
                                    Roger Stoltz
                                    wrote on last edited by
                                    #17

                                    toxcct wrote:

                                    Effective at any cost !

                                    I'm sure the customer would like to hear that slogan, tox'... ;) How about exchanging "any" for "less"?

                                    "It's supposed to be hard, otherwise anybody could do it!" - selfquote
                                    "High speed never compensates for wrong direction!" - unknown

                                    T 1 Reply Last reply
                                    0
                                    • R Roger Stoltz

                                      toxcct wrote:

                                      Effective at any cost !

                                      I'm sure the customer would like to hear that slogan, tox'... ;) How about exchanging "any" for "less"?

                                      "It's supposed to be hard, otherwise anybody could do it!" - selfquote
                                      "High speed never compensates for wrong direction!" - unknown

                                      T Offline
                                      T Offline
                                      toxcct
                                      wrote on last edited by
                                      #18

                                      f*ck the customers off ! lol. we work for a better code and I don't like people telling me to code crap because a moron wants it earlier...

                                      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                                      R 1 Reply Last reply
                                      0
                                      • T toxcct

                                        f*ck the customers off ! lol. we work for a better code and I don't like people telling me to code crap because a moron wants it earlier...

                                        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                                        R Offline
                                        R Offline
                                        Roger Stoltz
                                        wrote on last edited by
                                        #19

                                        toxcct wrote:

                                        we work for a better code and I don't like people telling me to code crap because a moron wants it earlier...

                                        I'm right beside you on the barricades, possibly with my back full of arrows 'cause that's how the pioneers are recognized. :-D

                                        "It's supposed to be hard, otherwise anybody could do it!" - selfquote
                                        "High speed never compensates for wrong direction!" - unknown

                                        1 Reply Last reply
                                        0
                                        • T toxcct

                                          well, let's imagine the smarter/most effective language in the world. how many lines of code de you think it would be for Windows to be written ?

                                          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                                          R Offline
                                          R Offline
                                          Rage
                                          wrote on last edited by
                                          #20

                                          toxcct wrote:

                                          how many lines of code de you think it would be for Windows to be written

                                          an oneliner, or maybe two (kernel code): COperatingSystem co = new [OperatingSystem()]; co.Run(true); /* true to activate random bugs */

                                          T 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups