Boost logo

Boost :

From: Chris Lattner (clattner_at_[hidden])
Date: 2007-09-01 20:49:21


On Sep 1, 2007, at 3:23 PM, Mathias Gaunard wrote:
> Chris Lattner wrote:
>> David's characterization is somewhat correct, but is also a bit
>> simplistic. The LLVM project does certainly use templates (including
>> partial specialization etc), but we prefer to keep this as an
>> implementation detail in a library. Exposing "complex" template code
>> through the public interface of a library generally make the library
>> "scary" to those developers who don't consider themselves to be C++
>> gurus. This design point also reduces build time for the LLVM code
>> itself.
>
> From a rough sketch, I personally feel more scared by the pointers
> exposed everywhere -- which are one of the greatest sources of
> unsafety
> in C++ --, the non usage of RAII, the explicit casts and other unsafe
> things, the usage of downcasting everywhere etc.

This is an interesting assertion. In LLVM, we have had far more bugs
and other problems due to various subtle iterator invalidation issues
than due to any sort of pointer or memory lifetime problems. While
they may be your personal fear, they seem to work well for a lot of
code in practice.

> I had read that LLVM was supposed to be "finely crafted C++" but it
> looks more like the usual object-oriented C++ from the nineties
> that you
> see everywhere and that contributed to make C++'s reputation of a
> dangerous and unmaintainnable language.

I'm sure you're aware that "the usual object-oriented C++ from the
nineties" often is the best solution when you do have *dynamic*
polymorphism - as you do when processing ASTs and other compiler
IRs. Templates are great for solving problems involving static
polymorphism, and we certainly do apply them to such problems.

In any case, this hyperbole is wildly off-topic and not very useful.
If you have specific suggestions on improvements that can be made to
various LLVM APIs, please do bring it up on the appropriate LLVM
lists - we're always very interested in improving the system.

> I honestly don't understand how can people be "scared" to use
> templates,
> especially compiler writers, which should be able to understand how
> they
> work and what they do.

You need to talk to C programmers more often then. Not all compiler
engineers are C++ front-end hackers after all. I'm not interested in
artificially restricting the number of people who can contribute to
LLVM. Using templates for the sake of using templates isn't
interesting to me: using them where they add value is, and we
continue to do so.

> They don't add bloat unless you make them do so (especially with LLVM
> which should be able to remove all unused code and duplicates without
> any problem). On the contrary, they allow the design of thin layers
> for
> robust type safety as well as nice reusable wrappers.

Templates are a tool that can be used for good as well as for evil.
When misused, templates, like any other powerful tool, can be very
damaging to readability, compile time, and code size. When used
appropriately, then can be quite beneficial.

In any case, this discussion isn't very appropriate to the boost
list. If you want to suggest ways to improve LLVM, please do so in
the appropriate place: the LLVM list.

Thanks!

-Chris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk