What has C++ become?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • plenty900@yahoo.com

    What has C++ become?

    I was looking over someone's C++ code today and despite
    having written perfectly readable C++ code myself,
    the stuff I was looking at was worse than legalese.
    The people who are guiding the development of C++
    have really made a mess of things, I mean templates
    and competing libraries and all that just render the
    code impossible to comprehend. Sure there is
    going to be a certain amount of complexity,
    that's a given, but if code is not readable except by
    a kind of clergy then there is something wrong with
    the language. Of course, I suppose the code I was
    looking at could have been deliberately obfuscated
    so that the developer could maintain control over it,
    but shouldn't a language (or its libraries) be designed
    to prevent that?
  • jason.cipriani@gmail.com

    #2
    Re: What has C++ become?

    On May 31, 12:36 pm, plenty...@yahoo .com wrote:
    I was looking over someone's C++ code today and despite
    having written perfectly readable C++ code myself,
    the stuff I was looking at was worse than legalese.
    The people who are guiding the development of C++
    have really made a mess of things, I mean templates
    and competing libraries and all that just render the
    code impossible to comprehend. Sure there is
    going to be a certain amount of complexity,
    that's a given, but if code is not readable except by
    a kind of clergy then there is something wrong with
    the language. Of course, I suppose the code I was
    looking at could have been deliberately obfuscated
    so that the developer could maintain control over it,
    but shouldn't a language (or its libraries) be designed
    to prevent that?
    Not everybody is a good C++ writer. It's a combination of two things:

    1) A person not using the language as effectively as possible (and for
    many people there is nothing you can do about it other than accept it
    as inevitable). A poor legal writer can produce unusually unclear
    legal documents (some legalese is easier to understand than others).

    2) The ability to read it well (once you see enough strange looking
    code it starts to make more sense and doesn't look as confusing). An
    experienced lawyer can read even the most obtuse legalese document
    without much of a problem.

    The best thing that can be done to prevent that is to stop the problem
    at it's source (#1). Rather than trolling newsgroups with questions
    like this, which don't help anything at all, instead look for people
    with legitimate problems in their code and give them constructive
    criticism and suggestions.

    Jason

    Comment

    • =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=

      #3
      Re: What has C++ become?

      On 2008-05-31 18:36, plenty900@yahoo .com wrote:
      I was looking over someone's C++ code today and despite
      having written perfectly readable C++ code myself,
      the stuff I was looking at was worse than legalese.
      The people who are guiding the development of C++
      have really made a mess of things, I mean templates
      and competing libraries and all that just render the
      code impossible to comprehend.
      Sure, templates can be a bit hard to read before you get used to them
      (and template meta-programming even harder) but considering how powerful
      they are I do not think they are overly complex.

      As for competing libraries, that is something that all moderately
      successful languages have to deal with. There are always someone who
      thinks that the standard libraries are not good enough and starts their
      own. In some languages it is even worse with multiple standard libraries.
      Sure there is
      going to be a certain amount of complexity,
      that's a given, but if code is not readable except by
      a kind of clergy then there is something wrong with
      the language.
      Most code in non-trivial systems is hard to read if you are not familiar
      with the specific domain and the structure of the code. Good coding
      guidelines and a clear architecture will mitigate this but can never
      remove it entirely.

      --
      Erik Wikström

      Comment

      • peter koch

        #4
        Re: What has C++ become?

        On 31 Maj, 18:36, plenty...@yahoo .com wrote:
        I was looking over someone's C++ code today and despite
        having written perfectly readable C++ code myself,
        the stuff I was looking at was worse than legalese.
        The people who are guiding the development of C++
        have really made a mess of things, I mean templates
        and competing libraries and all that just render the
        code impossible to comprehend. Sure there is
        going to be a certain amount of complexity,
        that's a given, but if code is not readable except by
        a kind of clergy then there is something wrong with
        the language. Of course, I suppose the code I was
        looking at could have been deliberately obfuscated
        so that the developer could maintain control over it,
        but shouldn't a language (or its libraries) be designed
        to prevent that?
        Now I don't know what kind of code you did look at, but I remember
        first time I looked at a C program: it looked more or less like
        gibberish (I used to program in a Pascal variant with some assembly
        woven in). A few days practice, and I found the code readable, and
        after a few months I even liked it better than Pascal.
        So what it all came up to was a need to familiarise myself with the
        syntax and get acquainted to the principles behind C.
        I guess it is the same stuff that troubles you. Writing templated code
        is somewhat different from writing normal code: much more must take
        place at compile-time, but when you learn the tricks and the way
        things work, it is not so difficult again.
        Also, if you did look at some code that was either library code or
        code that was supposed to be supported to many (possibly old)
        platforms, you will likely see code that is seemingly somewhat
        obfuscated.
        Probably, a few days of dissecting the code will make you well
        comfortable with it: if not, you are welcome to ask questions here (or
        to your collegues, of course).

        /Peter

        Comment

        • James Kanze

          #5
          Re: What has C++ become?

          On May 31, 7:25 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
          On 2008-05-31 18:36, plenty...@yahoo .com wrote:
          I was looking over someone's C++ code today and despite
          having written perfectly readable C++ code myself,
          the stuff I was looking at was worse than legalese.
          The people who are guiding the development of C++
          have really made a mess of things, I mean templates
          and competing libraries and all that just render the
          code impossible to comprehend.
          Sure, templates can be a bit hard to read before you get used
          to them (and template meta-programming even harder) but
          considering how powerful they are I do not think they are
          overly complex.
          It's always a costs-benefits tradeoff. Making the code harder
          to read is a definite cost. Afterwards, you have to weigh the
          benefits, and see if they are worth it.

          --
          James Kanze (GABI Software) email:james.kan ze@gmail.com
          Conseils en informatique orientée objet/
          Beratung in objektorientier ter Datenverarbeitu ng
          9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

          Comment

          • coal@mailvault.com

            #6
            Re: What has C++ become?

            On May 31, 10:36 am, plenty...@yahoo .com wrote:
            I was looking over someone's C++ code today and despite
            having written perfectly readable C++ code myself,
            the stuff I was looking at was worse than legalese.
            The people who are guiding the development of C++
            have really made a mess of things, I mean templates
            and competing libraries and all that just render the
            code impossible to comprehend.

            I think competing libraries are going to be around for
            a while. Hybrid cars are selling well lately and
            I don't think that is going to change anytime soon.
            Perhaps surprisingly, the increased complexity and
            knowledge required to develop and maintain a hybrid
            doesn't overwhelm the relative total cost of ownership
            given high energy prices. By relative I mean relative
            to a car with only a gas engine.

            For whatever reason, the gas engine/"traditiona l C++"
            approach is not producing efficient results in some
            contexts -- http://webEbenezer.net/comparison.html.
            We're working on a new version of those tests that uses
            Boost 1.35 and MSVC9. The preliminary results show no
            significant differences from those using Boost 1.34.1 and
            MSVC8. We're also planning to expand the test cases.
            There are other reasons beside run-time performance that
            our approach may be successful. We believe our approach
            will also help improve build times. We aren't there yet,
            though as no one has provided automated support for
            integrating our services into the build process.
            Sure there is
            going to be a certain amount of complexity,
            that's a given, but if code is not readable except by
            a kind of clergy then there is something wrong with
            the language.
            I agree there is room for improvement with the language, but
            still don't really agree with your conclusion. Your mention
            of clergy is interesting... when it comes to providing
            thoughtful and helpful services, a good priest is essential.
            Of course, I suppose the code I was
            looking at could have been deliberately obfuscated
            so that the developer could maintain control over it,
            Unfortunately, I think that happens. It requires good
            leadership to deal with someone who behaves that way.


            Brian Wood
            Ebenezer Enterprises

            Comment

            • plenty900@yahoo.com

              #7
              Re: What has C++ become?

              On May 31, 3:57 pm, peter koch <peter.koch.lar ...@gmail.comwr ote:
              Now I don't know what kind of code you did look at, but I remember
              first time I looked at a C program: it looked more or less like
              gibberish (I used to program in a Pascal variant with some assembly
              woven in).
              I recall having the same experience, the *first* time I looked
              at a C program, having before that seen only Pascal,
              Modula-2, Basic and assembly. But I've seen C++ many times
              now, albeit mostly my own which is deliberately readable.


              Comment

              • plenty900@yahoo.com

                #8
                Re: What has C++ become?

                On Jun 1, 1:01 am, c...@mailvault. com wrote:
                Of course, I suppose the code I was
                looking at could have been deliberately obfuscated
                so that the developer could maintain control over it,
                >
                Unfortunately, I think that happens.  It requires good
                leadership to deal with someone who behaves that way.
                I should mention that this is open source code,
                so there is no leadership. Could be worse though,
                could be the Linux kernel.

                Comment

                • Walter Bright

                  #9
                  Re: What has C++ become?

                  James Kanze wrote:
                  On May 31, 7:25 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
                  >Sure, templates can be a bit hard to read before you get used
                  >to them (and template meta-programming even harder) but
                  >considering how powerful they are I do not think they are
                  >overly complex.
                  >
                  It's always a costs-benefits tradeoff. Making the code harder
                  to read is a definite cost. Afterwards, you have to weigh the
                  benefits, and see if they are worth it.
                  I don't believe readability is a cost benefit tradeoff. I attended Scott
                  Meyers' presentation at NWCPP (slides here:
                  http://www.nwcpp.org/Downloads/2008/code_features.pdf). Scott mentioned
                  that he'd had help from TMP experts in creating the code examples, so we
                  can discount the idea that the readability problems are caused by lack
                  of programmer ability in C++ TMP.

                  After looking at it for a while, it seems to me that there is no way to
                  lay out the whitespace to make it look right. C++ TMP simply eats up far
                  too much horizontal space.

                  Second of all, once you figure out what it is doing, what it is doing is
                  rather simple. It is just a very poor notation for that (which is
                  consistent with TMP for C++ being discovered rather than designed).

                  Is it necessary to have such a poor notation? I don't believe so. C++
                  TMP is an FP language, and other FP languages tend to have much better
                  notation.

                  ----------
                  Walter Bright
                  Digital Mars C, C++, D programming language compilers

                  Comment

                  • Juha Nieminen

                    #10
                    Re: What has C++ become?

                    plenty900@yahoo .com wrote:
                    I was looking over someone's C++ code today and despite
                    having written perfectly readable C++ code myself,
                    the stuff I was looking at was worse than legalese.
                    "Someone's C++ code"? Are you sure that "someone" is an experienced
                    C++ programmer who knows how to write good-quality understandable C++?

                    Anyone can write incomprehensibl e code with any language. And what is
                    worse, most people actually do.
                    The people who are guiding the development of C++
                    have really made a mess of things, I mean templates
                    and competing libraries and all that just render the
                    code impossible to comprehend.
                    What "competing libraries"?

                    And as for templates making a "mess of things", I'd say that's more
                    often than not just a myth. My personal experience is that templates
                    actually *simplify* things in most cases, they don't complicate things.
                    Just a small example:

                    int table[100];
                    ....
                    std::sort(table , table+100);

                    I believe that's pretty simple and understandable code, or would you
                    disagree? (Never mind the "table+100" pointer trickery. That's not the
                    point here.)

                    Well, you know what? That's template code. It's precisely *because* of
                    templates that that code can be so simple as it is. Without templates it
                    would have to be much more complicated (compare to C's qsort()).

                    Maybe you think using <makes template code "a mess"? I don't
                    understand why. Is this somehow unclear:

                    std::vector<int table;
                    table.push_back (5);

                    What's so unclear about that? I think it's perfectly clear and legible
                    code. How else would you want it to be?
                    Sure there is
                    going to be a certain amount of complexity,
                    that's a given, but if code is not readable except by
                    a kind of clergy then there is something wrong with
                    the language.
                    It's impossible to design a language so that it cannot be written in
                    an unclear way. It's always possible to write obfuscated code.

                    However, that doesn't mean it's impossible to write clear code.

                    Comment

                    • James Kanze

                      #11
                      Re: What has C++ become?

                      On Jun 2, 7:41 am, Walter Bright <wal...@digital mars-nospamm.com>
                      wrote:
                      James Kanze wrote:
                      On May 31, 7:25 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
                      Sure, templates can be a bit hard to read before you get used
                      to them (and template meta-programming even harder) but
                      considering how powerful they are I do not think they are
                      overly complex.
                      It's always a costs-benefits tradeoff. Making the code harder
                      to read is a definite cost. Afterwards, you have to weigh the
                      benefits, and see if they are worth it.
                      I don't believe readability is a cost benefit tradeoff.
                      It is in the sense that it's not binary. Totally unreadable
                      code has such high cost that nothing can outweigh it, but there
                      are times when you might give up a little bit of readability
                      (without the code becoming totally unreadable) if the other
                      benefits are large enough.
                      I attended Scott Meyers' presentation at NWCPP (slides
                      here:http://www.nwcpp.org/Downloads/2008/code_features.pdf).
                      Scott mentioned that he'd had help from TMP experts in
                      creating the code examples, so we can discount the idea that
                      the readability problems are caused by lack of programmer
                      ability in C++ TMP.
                      After looking at it for a while, it seems to me that there is
                      no way to lay out the whitespace to make it look right. C++
                      TMP simply eats up far too much horizontal space.
                      More to the point, the "language" isn't really designed for what
                      it is being used for. You need all sorts of strange constructs
                      to do fundamentally simple things, like loop or a conditional.
                      Second of all, once you figure out what it is doing, what it
                      is doing is rather simple. It is just a very poor notation for
                      that (which is consistent with TMP for C++ being discovered
                      rather than designed).
                      Is it necessary to have such a poor notation? I don't believe
                      so. C++ TMP is an FP language, and other FP languages tend to
                      have much better notation.
                      Exactly. Because they were designed with that in mind.

                      What it does mean is that you don't use TMP, at least in its
                      more complete forms, unless the benefits are extremely high, and
                      even then, probably only in contexts where you can be sure that
                      only real experts (who can cope with the loss of readability)
                      have to maintain it.

                      --
                      James Kanze (GABI Software) email:james.kan ze@gmail.com
                      Conseils en informatique orientée objet/
                      Beratung in objektorientier ter Datenverarbeitu ng
                      9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

                      Comment

                      • Walter Bright

                        #12
                        Re: What has C++ become?

                        Juha Nieminen wrote:
                        Maybe you think using <makes template code "a mess"? I don't
                        understand why.
                        It's because of the parsing ambiguities that come from using < as a
                        parameter delimiter.
                        Is this somehow unclear:
                        >
                        std::vector<int table;
                        table.push_back (5);
                        >
                        What's so unclear about that? I think it's perfectly clear and legible
                        code. How else would you want it to be?
                        It's the wordiness of it. If the code gets more complicated than such
                        trivial examples, it gets rather hard to visualize. I would want it to
                        use a much more compact notation, like maybe:

                        int[] table;
                        table ~= 5;

                        To me, it's like the difference between

                        assign(a,add(b, c))

                        and

                        a=b+c

                        Comment

                        Working...