Thread: Why do you find C++ better than C?

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    46

    Question Why do you find C++ better than C?

    Everything which can be done in C++ using the OOP concept can be done in C and C programs are way faster than C++ ones. Also C offers procedural execution which is far easier to understand than all that OOP stuff. Why is it then that people find C++ better than C?

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    89
    maybe because you get to use cout and cin instead of printf and
    scanf :P
    behold the faithless one and his angel

  3. #3
    Meow Pendragon's Avatar
    Join Date
    Sep 2001
    Location
    Swindon, UK
    Posts
    723
    A good question actually... I use both and don't really have a preference. Programming is a hobby to me at the moment.

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Large object-oriented programs are generally easier to understand, and therefore maintain than large procedural programs. C++ is also more type safe than C. The speed difference between C and C++ is more a matter of how the programs are written in C++ than how the languages and compilers are designed and can be reduced greatly by good optimization. Also, most programs do not have the need to be that fast, and the remaining time difference is not terribly important.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Why do you find C better than assembly? Everything you can do in C, you can do in asm, except it will probably be much faster in asm.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  6. #6
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    The code will be faster, the programming process won't.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  7. #7
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    C does not support object oriented programming or
    generic programming.

    Yea I'm sure you can write code that looks like
    Code:
    struct Car {
            struct Vtbl {
                      void (*startup)(void);
                      void (*draw)(void);
             };
    };
    And linked list which uses #defines to allow a template solution and in assembly the cut, paste and edit solution with your editor.

    C programs are way faster than C++ ones
    This depends alot more on your compiler than on the language.

    procedural execution
    C++ operates this way too, there's no defered
    operations or anything.

    Code:
    Car car("blue");         // constructor called
    car.draw();                // after constructor is called, call function to draw a car

  8. #8
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    > Everything which can be done in C++ using the OOP concept can be done in C and C programs are way faster than C++ ones.

    Don't confuse object-oriented programming with C++. For the same code compiled with a C and with a C++ compiler, there is no reason they should result in different code, and indeed they largely don't.

    An OOP program that is significantly slower than the optimal procedural equivalent is a poorly designed one. I find no basis for your question.

    > Also C offers procedural execution which is far easier to understand than all that OOP stuff.

    When you progress to writing and maintaining large programs, in which there is a significant amount of overlap between sections, you will understand the utility of object-oriented programming principles. There is no virtue in using iostreams over C streams; that does not mean there is no value in inheritance, polymorphism or separation of interface from implementation.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  9. #9
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    i prefer c++, it seems more optomized and also supports more features than c, (eg classes)
    Monday - what a way to spend a seventh of your life

  10. #10
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    > Everything which can be done in C++ using the OOP concept can be done in C... <

    And those C programs are most likely also C++ programs.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  11. #11
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    C++ is not always better than C and I think most people agree. This line of questioning eventually results in something like this:
    Each programming language is a tool.
    The more tools you have in your belt, the better and faster you can get things done.
    If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?

  12. #12
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    > Each programming language is a tool.
    The more tools you have in your belt, the better and faster you can get things done. <

    Excellent point. Thats why the old "whats the best language" argument never gets anywhere.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  13. #13
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    C++ is not always better than C and I think most people agree. This line of questioning eventually results in something like this:
    Each programming language is a tool.
    The more tools you have in your belt, the better and faster you can get things done.
    Consider, then, two screwdrivers: identical save that one can accept more stress. Do you consider that there is a time at which one would use the lesser one?

    C++ offers the same facilities that C does, using the same syntax and the same generated code quality. It offers everything C does, and can be used in its place with no loss of power, functionality or speed. Why, then, should one spurn C++ for C?

    There is only one time I would use a C compiler, and that is the case in which there is no C++ compiler available. I'm doing this at the moment with a Mitsubishi single-chip micro, and I miss C++'s abilities. Not the classes; the ability to declare variables other than at the start of a scope, the ability to drop the 'struct' keyword, namespaces. Little things, which don't affect the code quality, but help the programmer.

    C grows over time, just as any other programming language does. It can do so because the additions don't change its suitability. If you are able to accept the changes in C, why are you not able to accept the incremental changes in moving to C++?

    I repeat: C++ does not imply OOP.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  14. #14
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    C has its uses. C is a smaller language than C++, and is therefore more usable on machines with very little memory. This isn't a huge strength, but it is one.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  15. #15
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    I think this post would be better if we perhaps delved into when to use c vs c++.
    I use c++ for general programming, but as I was doing a project recently (encoding and decoding) I found it easier to use c for the encoding part and c++ for the decoding. I could just have used one or the other but I chose not too.
    I think I'm going to start a new post that gets into more than just c/c++ and when to use a programming language.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. could not find -lwsock32.lib
    By thomas_joyee in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2008, 12:28 PM
  3. How to find O of threads ?
    By jabka in forum C Programming
    Replies: 3
    Last Post: 03-11-2008, 12:25 PM
  4. how do u find 2nd largest number??
    By juancardenas in forum C Programming
    Replies: 8
    Last Post: 02-14-2003, 08:28 AM
  5. Q: Recursion to find all paths of a maze
    By reti in forum C Programming
    Replies: 7
    Last Post: 11-26-2002, 09:28 AM