Why C++ is vastly superior to C

Discussion in 'C++' started by Lynn McGuire, May 16, 2011.

  1. Lynn McGuire

    Lynn McGuire Guest

    Why C++ is vastly superior to C:
    http://warp.povusers.org/programming/cplusplus_superior_to_c.html

    "In conclusion, the reason why C is so vastly inferior to C++ as
    described in this article can be summarized with one single sentence:
    C has no support for RAII nor templates, while C++ does. That's two
    of the most important features that make C++ by far the superior
    language."

    Lynn
     
    Lynn McGuire, May 16, 2011
    #1
    1. Advertising

  2. Lynn McGuire

    crea Guest

    "Lynn McGuire" <> wrote in message
    news:iqremk$ltg$...
    > Why C++ is vastly superior to C:
    > http://warp.povusers.org/programming/cplusplus_superior_to_c.html
    >
    > "In conclusion, the reason why C is so vastly inferior to C++ as
    > described in this article can be summarized with one single sentence:
    > C has no support for RAII nor templates, while C++ does. That's two
    > of the most important features that make C++ by far the superior
    > language."


    the main thing is the object oriented approach, i guess. Also many improved
    version of functions
     
    crea, May 16, 2011
    #2
    1. Advertising

  3. Lynn McGuire

    Balog Pal Guest

    "Lynn McGuire" <>

    > Why C++ is vastly superior to C:
    > http://warp.povusers.org/programming/cplusplus_superior_to_c.html
    >
    > "In conclusion, the reason why C is so vastly inferior to C++ as
    > described in this article can be summarized with one single sentence:
    > C has no support for RAII nor templates, while C++ does. That's two
    > of the most important features that make C++ by far the superior
    > language."


    Quite so. Another "most important" feature was parting with "locals at block
    start", but it got into C99 in the mantime. (too bad that real-world C is
    still at C90, a decade+ after the last revision, and massive projects still
    stick to that old known bug generator. :( )
     
    Balog Pal, May 16, 2011
    #3
  4. Lynn McGuire

    Krice Guest

    On 16 touko, 18:08, Lynn McGuire <> wrote:
    > "In conclusion, the reason why C is so vastly inferior to C++ as
    > described in this article can be summarized with one single sentence:
    > C has no support for RAII nor templates, while C++ does. That's two
    > of the most important features


    You can live without templates, it's the least important feature
    of C++ and people constantly over/misuse it. Most important feature
    is class programming: instances, encapsulation and inheritance,
    the OOP basics.
     
    Krice, May 16, 2011
    #4
  5. Krice <> wrote:
    > On 16 touko, 18:08, Lynn McGuire <> wrote:
    >> "In conclusion, the reason why C is so vastly inferior to C++ as
    >> described in this article can be summarized with one single sentence:
    >> C has no support for RAII nor templates, while C++ does. That's two
    >> of the most important features

    >
    > You can live without templates, it's the least important feature
    > of C++ and people constantly over/misuse it. Most important feature
    > is class programming: instances, encapsulation and inheritance,
    > the OOP basics.


    I disagree.

    Encapsulation and instantiation are extremely important, yes, but you
    can achieve that to a certain degree in C as well. Access rights might
    not be enforced by the language (except on the compilation unit level),
    but you can achieve this to a certain degree by agreement (iow. "don't
    touch anything inside this struct"). Yes, this is not perfect, but it's
    not catastrophical either. This is not the main reason why C is inferior
    to C++.

    Inheritance is useful in some situations, but it's far less useful than
    was thought at the height of the OOP craze in the 90's. It definitely has
    its uses, but it has its shortcomings as well. It is an important feature,
    but I would certainly not rank it higher than RAII and templates.

    As for templates, I fully disagree: A C++ without templates would be
    almost as horrible as C is. (RAII would still make it by far superior,
    but the lack of templates would be a huge setback nevertheless.)

    If you can live without templates, how would you implement the last
    challenge in the article (iow. making the example Matrix class generic,
    to support any numerical type, including those which do not behave like
    basic types)?

    On the same note, how would you make generic data containers and
    algorithms which are as efficient as possible? (Note their prominent
    absence in standard C; there's a reason for that.) Other programming
    languages manage by other means, but they often suffer from poorer
    efficiency (especially in the memory consumption department, sometimes
    also in the speed one).
     
    Juha Nieminen, May 16, 2011
    #5
  6. Juha Nieminen, May 16, 2011
    #6
  7. Lynn McGuire

    Lynn McGuire Guest

    On 5/16/2011 11:29 AM, Krice wrote:
    > On 16 touko, 18:08, Lynn McGuire<> wrote:
    >> "In conclusion, the reason why C is so vastly inferior to C++ as
    >> described in this article can be summarized with one single sentence:
    >> C has no support for RAII nor templates, while C++ does. That's two
    >> of the most important features

    >
    > You can live without templates, it's the least important feature
    > of C++ and people constantly over/misuse it. Most important feature
    > is class programming: instances, encapsulation and inheritance,
    > the OOP basics.


    I could not live without the Standard Template Library.

    Lynn
     
    Lynn McGuire, May 16, 2011
    #7
  8. Lynn McGuire

    Öö Tiib Guest

    On May 16, 7:37 pm, Leigh Johnston <> wrote:
    > On 16/05/2011 17:29, Krice wrote:
    >
    > > On 16 touko, 18:08, Lynn McGuire<>  wrote:
    > >> "In conclusion, the reason why C is so vastly inferior to C++ as
    > >> described in this article can be summarized with one single sentence:
    > >> C has no support for RAII nor templates, while C++ does. That's two
    > >> of the most important features

    >
    > > You can live without templates, it's the least important feature
    > > of C++ and people constantly over/misuse it. Most important feature
    > > is class programming: instances, encapsulation and inheritance,
    > > the OOP basics.

    >
    > I disagree; generic programming is just as important as object oriented
    > programming.


    +1.

    Encapsulation can be done well in C. Just like the FILE* in C library.
    You know nothing about it but the functions ("methods") with what you
    can manipulate one. Similarly abstract interfaces and polymorphism can
    be implemented in C with function pointers. There is some semantic
    overhead but that can be reduced with macros. It is easy to write
    small quick programs in pure C.

    C++ however scales well. Templates in interface simplify integration
    of your code with a library by huge margin. The big legacy C++
    libraries have gradually increased presence of templates in their
    interface. In boost and in Loki the templates are sometimes overused
    but that is because the authors were curious and like to explore the
    possibilities.

    RAII is great way to reduce the need for garbage collection. Being
    careful you create no garbage. The usual garbage collection takes care
    of least important resource ... the memory. I have started to hate
    Windows lately because some of the garbage collected crap has left
    files open and so i can't delete those without closing all the
    applications. Also the applications start back up slowly like snails.
     
    Öö Tiib, May 16, 2011
    #8
  9. Lynn McGuire

    Nobody Guest

    On Mon, 16 May 2011 09:29:07 -0700, Krice wrote:

    > You can live without templates, it's the least important feature
    > of C++ and people constantly over/misuse it. Most important feature
    > is class programming: instances, encapsulation and inheritance,
    > the OOP basics.


    Maybe for you. OTOH, if performance matters, templates are essential.
    And if performance doesn't matter, higher-level languages offer the OOP
    features with less hassle. IOW, if you don't need templates, you probably
    don't need C++ either.
     
    Nobody, May 16, 2011
    #9
  10. Lynn McGuire

    Krice Guest

    On 16 touko, 20:36, Lynn McGuire <> wrote:
    > I could not live without the Standard Template Library.


    Mostly because core C++ doesn't have something like std::string
    or vector. If I need to write a template (beside using STL)
    I know there is something wrong with the class hierarchy. It's
    like using cast, you know it's a workaround to a design error.
     
    Krice, May 16, 2011
    #10
  11. On May 16, 10:53 am, Nobody <> wrote:
    > On Mon, 16 May 2011 09:29:07 -0700, Krice wrote:
    > > You can live without templates, it's the least important feature
    > > of C++ and people constantly over/misuse it. Most important feature
    > > is class programming: instances, encapsulation and inheritance,
    > > the OOP basics.

    >
    > Maybe for you. OTOH, if performance matters, templates are essential.


    I want to emphasize this. Templates are nice for code reuse, but
    several posters ignored IMHO the most important aspect of their
    utility. Templates allow generic code and code reuse without runtime
    overhead. For too many people, and for some people with legitimate
    concerns, there is almost a knee-jerk fear of runtime overhead, and
    thus they would rather roll their own, every time, instead of use a
    standard library or well tested, well optimized, library solution,
    because of the overhead that using a non-template library would
    impose.

    Take C's sort. The comparator function is a function pointer, and the
    last I heard is that most compilers simply will not expand that
    inline, as opposed to C++ various sort functions which can be expanded
    inline.
     
    Joshua Maurice, May 16, 2011
    #11
  12. Lynn McGuire

    Balog Pal Guest

    "Krice" <>
    > On 16 touko, 20:36, Lynn McGuire <> wrote:
    >> I could not live without the Standard Template Library.

    >
    > Mostly because core C++ doesn't have something like std::string
    > or vector.


    String could very well be a simple class, but how do you create a good
    vector without templates? Do you suggest to go back to only have the
    "Object-based" polymorphic array? Even java failed miserably on that point,
    if you recall the hype raving that templates are not good and would never
    make it into a cool language of theirs. Finally generics were incorporated
    around 1.5 -- mainly to cover the mass problems with collections. :)

    > If I need to write a template (beside using STL)
    > I know there is something wrong with the class hierarchy.


    The most ubiquitous problem with class hierarchy is thet you don't need one
    in the first place.
    Sure, having hierarchy is great for some particular cases, I both used and
    wrote such, but it is in minority by far.

    > It's like using cast, you know it's a workaround to a design error.


    I don't see any likeness. Hierarchy is good for runtime polymorphism, while
    templates cover the common case where the type is fixed at compile time.
     
    Balog Pal, May 16, 2011
    #12
  13. Lynn McGuire

    Ebenezer Guest

    On May 16, 12:25 pm, Juha Nieminen <> wrote:
    > Lynn McGuire <> wrote:
    > > Why C++ is vastly superior to C:
    > >    http://warp.povusers.org/programming/cplusplus_superior_to_c.html

    >
    >   I'm glad I'm not writing those articles just for myself... :)


    Also from the conclusion:
    "The example I described in this lengthy article is but just one of
    the reasons why C is so vastly inferior to C++."

    The "but just one" part is not common usage. You could
    use "but one of ..." or "just one of ..." I think the latter
    would be good. I think I'd cut the vastly word also -- "so
    inferior" pretty much covers it.
     
    Ebenezer, May 16, 2011
    #13
  14. Lynn McGuire

    Rui Maciel Guest

    Krice wrote:

    > Mostly because core C++ doesn't have something like std::string
    > or vector.


    Why would anyone extend the base language to incorporate something which
    is easily implemented (and, better yet, extendable) through other basic
    language constructs?


    > If I need to write a template (beside using STL)
    > I know there is something wrong with the class hierarchy.


    Do you know how I can tell you aren't a good programmer?


    Rui Maciel
     
    Rui Maciel, May 16, 2011
    #14
  15. Lynn McGuire

    Rui Maciel Guest

    Balog Pal wrote:

    > Quite so. Another "most important" feature was parting with "locals at
    > block start", but it got into C99 in the mantime. (too bad that
    > real-world C is still at C90, a decade+ after the last revision, and
    > massive projects still stick to that old known bug generator. :( )


    What do you mean by "real-world C is still at C90"?


    Rui Maciel
     
    Rui Maciel, May 16, 2011
    #15
  16. Lynn McGuire

    Ian Collins Guest

    On 05/17/11 08:21 AM, Rui Maciel wrote:
    > Balog Pal wrote:
    >
    >> Quite so. Another "most important" feature was parting with "locals at
    >> block start", but it got into C99 in the mantime. (too bad that
    >> real-world C is still at C90, a decade+ after the last revision, and
    >> massive projects still stick to that old known bug generator. :( )

    >
    > What do you mean by "real-world C is still at C90"?


    C99 compilers are by no means universal. A lot of embedded (the
    majority of C projects) projects are still stuck with C90 tools.

    --
    Ian Collins
     
    Ian Collins, May 16, 2011
    #16
  17. Krice <> wrote:
    > If I need to write a template (beside using STL)
    > I know there is something wrong with the class hierarchy. It's
    > like using cast, you know it's a workaround to a design error.


    What happens when the STL is not enough? There are myriads of different
    data containers out there, and the STL only offers about 5 of them.

    Why is it a design error to make your libraries generic and reusable?
    That sounds to me like the exact opposite.
     
    Juha Nieminen, May 16, 2011
    #17
  18. Lynn McGuire

    Ian Collins Guest

    On 05/17/11 03:08 AM, Lynn McGuire wrote:
    > Why C++ is vastly superior to C:
    > http://warp.povusers.org/programming/cplusplus_superior_to_c.html
    >
    > "In conclusion, the reason why C is so vastly inferior to C++ as
    > described in this article can be summarized with one single sentence:
    > C has no support for RAII nor templates, while C++ does. That's two
    > of the most important features that make C++ by far the superior
    > language."


    I normally just use RAII as the reason. Everything else else can be
    kludged in C, but not RAII.

    --
    Ian Collins
     
    Ian Collins, May 16, 2011
    #18
  19. Lynn McGuire

    Krice Guest

    On 16 touko, 23:11, Rui Maciel <> wrote:
    > Do you know how I can tell you aren't a good programmer?


    I'm the first person in the world who wrote a roguelike with zero
    bugs.
    A thing like that didn't even exist before I made that possible.
    I'm not good, I'm the best.
     
    Krice, May 16, 2011
    #19
  20. Ian Collins <> wrote:
    > I normally just use RAII as the reason. Everything else else can be
    > kludged in C, but not RAII.


    It's quite difficult to kludge any kind of generic data containers in C
    (which is probably the reason why the standard C library does not offer
    any such containers). You could achieve something similar with preprocessor
    macros, but it would be quite limited, and definitely less safe (in big
    part because of the lack of RAII, constructors, destructors, etc).

    You could perhaps make some more or less generic containers for basic
    types and structs which only contain basic types (but not pointers) with
    preprocessor macros, but immediately when you need more resource management
    than that (such as a struct that as pointers pointing to dynamically
    allocated memory or other such resources) it becomes complicated. For that
    same reason it's complicated to make the containers nested. (Assigning
    a container object would not be the same as assigning a basic type.)

    It's so much simpler with C++ templates. Just write any amount of
    nested containers you want, no problem.

    std::deque<std::list<std::vector<std::set<std::string> > > > container;
     
    Juha Nieminen, May 16, 2011
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Sedlak
    Replies:
    6
    Views:
    368
    John Sedlak
    Nov 4, 2003
  2. vnssoftware
    Replies:
    9
    Views:
    372
    Douwe
    Aug 27, 2003
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,261
    Smokey Grindel
    Dec 2, 2006
  4. Öö Tiib
    Replies:
    11
    Views:
    505
    Öö Tiib
    May 20, 2010
  5. jacob navia

    Why C is vastly superior to C++

    jacob navia, Jun 28, 2011, in forum: C++
    Replies:
    27
    Views:
    996
    Juha Nieminen
    Jul 8, 2011
Loading...

Share This Page