I wonder what abuse of C++ templates you are looking at, as for myself I find the ATL library particulary abusing of C++ templates.

The author of the atrocity had obviously heard that templates were "efficient", so they implemented their little (little - hah!) stream reading class with templates.

Except there was a bunch of different behaviour depending on the object so they were continually checking objects typeid() to decide what to do in an massive evil switch statement, which triggered off what looked (after considerable pondering) like the guts of some kind of expression template. Which would be fair enough if there were any chains of expression to optimise out. Since there aren't it's a couple of hundred lines of fardling no-op.

The most annoying thing is that it's a massive case of the first law of optimisation (i.e. "don't"). The stuff this monstrosity deals with doesn't happen often, it's running on a machine with oodles of memory, it's taking data of the net and a database so the bottleneck is definitely not the code, etc.

Not to mention the fact they invented there own string class! Twice! Use templates badly and then ignore the STL. Fantastic.

If they'd just written it as plain C++ classes with sensible use of the STL it would be a quarter the size, work just as well and be perfectly obvious code.

I'm going to go write some Ruby so I can feel clean again :-)


In reply to Re^4: Static typing is mostly a waste of time by adrianh
in thread Static typing is mostly a waste of time by johnnywang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.