TexBlog

Steve Teixeira's Blog -- Thoughts on parallel computing, Microsoft, the industry, and life

Hmmm, maybe I shouldn't have set the write-only bit...

Hmmm, maybe I shouldn't have set the write-only bit...

  • Comments 5

Great article from Peter Coffee on the dangers of clever coding.  Developers, take heed: unless you're Hemingway, there is no virtue in terseness (and even for him, things didn't work out all that grandly).  Of course, the C language notoriously provides the flexibility to out-clever oneself into crazy obscure bugs.  C++ is much better in this regard but still provides a fine set of tools for the determined developer to ensure the compiler can't do its job of helping to identify bugs before the code is executed.

The classic counter argument offered by some C/C++ developers is, "well, I need the flexibility such-and-such wacky syntax allows for." This argument is, of course, a fallacy.  There is no dial between flexibility and maintainability, where one must chose some setting between the two.  Rather, flexibility and maintainability are orthogonal concepts.  It's entirely possible to write software to satisfy any number of constraints, such as high performance requirements or limited memory conditions, while still ensuring that such code is maintainable and modular.

Thanks to Nick for the pointer.

  • Unfortunately the example isn't an example of the rule that you're mentioning here.  True as the rule is, the rule is addressed towards individuals, warning them not to outwit themselves.  The primary target of the rule is programmers.

    The bug in this case was due to a programmer who made a trivial mistake, who didn't get an error message and was unaware of the logic error.  The programmer wasn't trying to be too clever for the programmer's self.  The programmer wasn't trying to be clever at all.  The language design was too clever.

    Theoretically, in language design you need to avoid being too clever for yourself AND avoid being too clever for programmers who will use the language.  Unfortunately in practical terms this kills a language.  Clever programmers want to use a language where they will outwit themselves, and then average programmers have to follow in their footsteps.

    Interesting that you bring up a bug in language design on the same day as one of your famous colleagues brought up another bug in language design, not far distant from yours.
  • Hi Norm, I think my example is related; it's Ritchey I would accuse of being a little too clever here in the C language design.  :)

    BTW, what was the other language design bug brought up yesterday?
  • > it's Ritchey I would accuse of being a little too clever
    > here in the C language design.

    That's exactly what I said.  Please reread the second paragraph in my previous comment.  Though the example is related, the example isn't a case of the programmer being too clever for the programmer's self.

    > BTW, what was the other language design bug brought
    > up yesterday?

    Sometimes C++ automatically does implicit conversions using constructors when the programmer wasn't expecting it.

    http://blogs.msdn.com/oldnewthing/archive/2006/05/24/605974.aspx
  • PingBack from http://quickdietsite.info/story.php?id=6409

Page 1 of 1 (5 items)