Debugging C vs debugging C++

Discussion in 'C Programming' started by jacob navia, Oct 26, 2006.

  1. jacob navia

    jacob navia Guest

    I was browsing the web pages of les haltton, a software engineering
    professor ( http://www.leshaltton.org ) and I found this data in

    htp://www.leshatton.org/Documents/dross_2006.pdf

    < begin quote >
    Summary of known measurements
    • C++ OO systems have comparable defect densities to conventional C or
    Pascal systems.
    • Each defect in a C++ OO system takes about twice as long to fix as in
    a conventional system.

    This is true for both simple defects AND difficult ones. The whole
    distribution is right shifted.
    • Components using inheritance have been observed to have 6 times the
    defect density.

    How much of this is attributable to C++ is unknown.

    < end quote >

    It is obvious that beside the much touted hype, OO systems have
    not brought any real improvement to C. The problem is in my
    opinion, the staggering complexity of those systems, what
    makes debugging thema nightmare unless you wrote them.

    jacob
    jacob navia, Oct 26, 2006
    #1
    1. Advertising

  2. jacob navia wrote:

    > I was browsing the web pages of les haltton, a software engineering
    > professor ( http://www.leshaltton.org ) and I found this data in


    It's hatton not hallton. Do you think you could check your
    links before posting them or at least afterwards ?

    > htp://www.leshatton.org/Documents/dross_2006.pdf
    >
    > < begin quote >
    > Summary of known measurements
    > · C++ OO systems have comparable defect densities to conventional C or
    > Pascal systems.
    > · Each defect in a C++ OO system takes about twice as long to fix as in
    > a conventional system.
    >
    > This is true for both simple defects AND difficult ones. The whole
    > distribution is right shifted.
    > · Components using inheritance have been observed to have 6 times the
    > defect density.
    >
    > How much of this is attributable to C++ is unknown.
    >
    > < end quote >
    >
    > It is obvious that beside the much touted hype, OO systems have
    > not brought any real improvement to C. The problem is in my
    > opinion, the staggering complexity of those systems, what
    > makes debugging thema nightmare unless you wrote them.


    This looks like comp.programming to me.
    Spiros Bousbouras, Oct 26, 2006
    #2
    1. Advertising

  3. Spiros Bousbouras wrote:

    > jacob navia wrote:
    >
    > > I was browsing the web pages of les haltton, a software engineering
    > > professor ( http://www.leshaltton.org ) and I found this data in

    >
    > It's hatton not hallton. Do you think you could check your
    > links before posting them or at least afterwards ?


    Not haltton either ;-)
    Spiros Bousbouras, Oct 26, 2006
    #3
  4. jacob navia

    jacob navia Guest

    jacob navia, Oct 26, 2006
    #4
  5. jacob navia wrote:


    > It is obvious that beside the much touted hype, OO systems have
    > not brought any real improvement to C. The problem is in my
    > opinion, the staggering complexity of those systems, what
    > makes debugging them a nightmare unless you wrote them.
    >
    > jacob


    IMHO the whole OO thing is mostly smoke and mirrors. Looked at from a
    height, how likely is it the first, (well, about the fourth,) major
    refactoring of the coding process is likely to be the final, universal,
    and unsullied panacea? Especially when it was grafted onto a
    less-than-perfect second try at a system language?

    The whole business of abstraction sounds really cool at first glance.
    The coolness wears off a bit when you have to work with real code,
    which after three or four different minds have layered abstractiuon
    upon abstraction, often is so abstract as to be uninterpretable by any
    human mind.

    I'm thinking in particular of one program, where an experienced
    programmer was asked to add just ONE small option. After peering thru
    thousands of lines of C++ code, he found it was easier to write a
    completely separate function to do the option, just five lines of code,
    rather than to try to insert TWO lines of code in the complex abstract
    hierarchy.

    IMHO giving a huge box of TinkerToys to toddlers does not result in
    amazingly robust edifices.
    Ancient_Hacker, Oct 26, 2006
    #5
  6. jacob navia

    jacob navia Guest

    Ancient_Hacker wrote:
    > I'm thinking in particular of one program, where an experienced
    > programmer was asked to add just ONE small option. After peering thru
    > thousands of lines of C++ code, he found it was easier to write a
    > completely separate function to do the option, just five lines of code,
    > rather than to try to insert TWO lines of code in the complex abstract
    > hierarchy.


    This is exactly the problem any C++ maintainer is facing.
    You have to understand the whole hierarchy, layered in several
    dozens of files to be able to just modify a small part of it.

    Hierarchy can be a good abstraction *sometimes* but the
    problem appears when you try to force it to EVERY
    situation.
    jacob navia, Oct 26, 2006
    #6
  7. jacob navia

    Guest

    jacob navia wrote:
    > I was browsing the web pages of les haltton, a software engineering
    > professor ( http://www.leshaltton.org ) and I found this data in
    >
    > htp://www.leshatton.org/Documents/dross_2006.pdf
    >
    > < begin quote >
    > Summary of known measurements
    > · C++ OO systems have comparable defect densities to conventional C or
    > Pascal systems.
    > · Each defect in a C++ OO system takes about twice as long to fix as in
    > a conventional system.
    >
    > This is true for both simple defects AND difficult ones. The whole
    > distribution is right shifted.
    > · Components using inheritance have been observed to have 6 times the
    > defect density.
    >
    > How much of this is attributable to C++ is unknown.
    >
    > < end quote >
    >
    > It is obvious that beside the much touted hype, OO systems have
    > not brought any real improvement to C. The problem is in my
    > opinion, the staggering complexity of those systems, what
    > makes debugging thema nightmare unless you wrote them.



    The defect density thing does not surprise me at all. I've seen
    similar studies going back decades, looking at many different languages
    and programming styles. The defect density in terms of bugs/kloc is
    fairly constant from assembler, to Cobol, to Lisp, to C to C++, to
    Haskel, to Forth to...

    It's also been observed that programmer productivity in klocs/month is
    also fairly constant between langauges.

    That defects are more difficult to fix in a more complex hierarchy or
    structure is also no surprise.

    To a large extent, the language that lets you write the smallest
    program "wins." To the extent that OO allows larger, more complex,
    applications to be built with a given amount of work, it's a win.

    OO certainly has is share of excessive hype, but there's a large class
    of application for which it is quite well suited. C++, in particular,
    is easy to abuse (and even hard to not abuse by accident), even more so
    than C. Many of the bugs you see in C++ code you'd *never* see in
    Smalltalk (or even C# or Java). Stroustrup himself said that while C
    makes it easy to shoot yourself in the foot, C++ lets you blow your
    whole leg off.
    , Oct 27, 2006
    #7
  8. jacob navia

    Guest

    jacob navia wrote:
    > I was browsing the web pages of les haltton, a software engineering
    > professor ( http://www.leshaltton.org ) and I found this data in
    >
    > htp://www.leshatton.org/Documents/dross_2006.pdf
    >
    > < begin quote >
    > Summary of known measurements
    > · C++ OO systems have comparable defect densities to conventional C or
    > Pascal systems.
    > · Each defect in a C++ OO system takes about twice as long to fix as in
    > a conventional system.
    >
    > This is true for both simple defects AND difficult ones. The whole
    > distribution is right shifted.
    > · Components using inheritance have been observed to have 6 times the
    > defect density.
    >
    > How much of this is attributable to C++ is unknown.
    >
    > < end quote >
    >
    > It is obvious that beside the much touted hype, OO systems have
    > not brought any real improvement to C. The problem is in my
    > opinion, the staggering complexity of those systems, what
    > makes debugging thema nightmare unless you wrote them.


    I'm the last person in the world to defend C++ over C, however, these
    statements are missing some very important considerations.

    1) You can accomplish *more* in C++ per line of code. Its not
    drastically more, but its definately more. Constructors and
    destructors are often called by default, you have exception handling
    which means you don't have to write very convoluted clean up code for
    successfully backing out of errors, and you have templates which means
    algorithms can truly be reused over different types. So in essence
    this analysis fails the typical "lines of code" fallacy.

    2) The *severity* of defects for the two languages is also very
    different. Many of the containers in STL remove the need to use
    pointers and "by hand" memory management. So a lot of things like "use
    after free", pointing to non-sense, uninitialized pointers, and
    ordinary buffer overflows, will tend to be less frequent in C++. The
    real problem is that C++ introduces a totally new programming paradigm
    which in of itself has built-in potential for errors that raw C doesn't
    have. Thus this analysis treats all kinds of errors as if they are the
    same as well.

    3) C++ is not the only embodiment of OO. Other languages such as Java,
    Ruby, Python and Lua have their own notion of OO programming. Its
    obvious that in these languages, errors are less severe, the rate of
    error production is code is far less, and the productivity per line of
    code is also much higher. So I don't think that "OO" is, in
    particular, either a culprit or an antagonist to reducing the number of
    errors in a program.

    --
    Paul Hsieh
    http://www.pobox.com/~qed/
    http://bstring.sf.net/
    , Oct 27, 2006
    #8
  9. jacob navia

    Ian Collins Guest

    jacob navia wrote:
    > I was browsing the web pages of les haltton, a software engineering
    > professor ( http://www.leshaltton.org ) and I found this data in
    >
    > htp://www.leshatton.org/Documents/dross_2006.pdf
    >
    > < begin quote >
    > Summary of known measurements
    > • C++ OO systems have comparable defect densities to conventional C or
    > Pascal systems.
    > • Each defect in a C++ OO system takes about twice as long to fix as in
    > a conventional system.
    >
    > This is true for both simple defects AND difficult ones. The whole
    > distribution is right shifted.
    > • Components using inheritance have been observed to have 6 times the
    > defect density.
    >
    > How much of this is attributable to C++ is unknown.
    >
    > < end quote >
    >
    > It is obvious that beside the much touted hype, OO systems have
    > not brought any real improvement to C. The problem is in my
    > opinion, the staggering complexity of those systems, what
    > makes debugging thema nightmare unless you wrote them.
    >

    Unless they have a decent set of unit tests.

    <ducks and runs for cover>

    --
    Ian Collins.
    Ian Collins, Oct 27, 2006
    #9
  10. Ian Collins wrote:


    > Unless they have a decent set of unit tests.
    >
    > <ducks and runs for cover>
    >
    > --
    > Ian Collins.


    better duck!

    (1) It's rare to see any extensive tests.

    (2) If the tests are written by the original coders, they have too
    much of a vested interest in not poking at their code too hard. Plus
    they know subconciously what not to try.

    (3) And of course even a full set of tests, even hundreds, cannot ever
    guarantee the absence of errors-- they can only at best point out
    errors.

    Remember the first space shuttle launch attempt-- even with an
    exemplary testing methodology they got egg on their faces really badly.
    Ancient_Hacker, Oct 27, 2006
    #10
  11. jacob navia

    CBFalconer Guest

    Ancient_Hacker wrote:
    >

    .... snip ...
    >
    > (2) If the tests are written by the original coders, they have
    > too much of a vested interest in not poking at their code too
    > hard. Plus they know subconciously what not to try.


    That is a sad commentary on the coders you have encountered. In my
    experience they know where the boundary conditions are, and write
    tests to explore those.

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>
    CBFalconer, Oct 27, 2006
    #11
  12. jacob navia

    Ian Collins Guest

    Ancient_Hacker wrote:
    > Ian Collins wrote:
    >
    >
    >
    >>Unless they have a decent set of unit tests.
    >>
    >><ducks and runs for cover>
    >>

    >
    > better duck!
    >
    > (1) It's rare to see any extensive tests.
    >
    > (2) If the tests are written by the original coders, they have too
    > much of a vested interest in not poking at their code too hard. Plus
    > they know subconciously what not to try.
    >

    <pops head up>
    That's why you write the tests first!

    --
    Ian Collins.
    Ian Collins, Oct 27, 2006
    #12
    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. Rob Tillie

    Garbage Collector Debugging

    Rob Tillie, Aug 15, 2003, in forum: ASP .Net
    Replies:
    11
    Views:
    1,741
    JerryK
    Aug 18, 2003
  2. ^CrazyCoder^
    Replies:
    3
    Views:
    7,241
    Terrence Benade
    Sep 15, 2003
  3. Cristina Cristina

    Debugging ASP.net Solution

    Cristina Cristina, Sep 17, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    416
    Cristina Cristina
    Sep 17, 2003
  4. Johann Blake
    Replies:
    1
    Views:
    1,188
    Hermit Dave
    Jan 5, 2004
  5. AAaron123
    Replies:
    3
    Views:
    648
    AAaron123
    Jul 28, 2009
Loading...

Share This Page