Boost logo

Boost :

Subject: Re: [boost] Review of a safer memory management approach for C++?
From: joel falcou (joel.falcou_at_[hidden])
Date: 2010-06-05 10:40:01


Bartlett, Roscoe A wrote:
> 1) Well written OO C++ software builds and (more importantly) rebuilds *much* faster than heavily templated code. This massively speeds up the development cycle. The difference can be orders of magnitude of time savings in recompile/relink times. I have seen cases where carefully using runtime OO can result in recompile/relink cycles take less than 20 seconds where using all template code would take 20 minutes. I am *not* exaggerating here at all.
>
You have the right to write proper, fast to compile template code.
Technics and tools exists for this. And if your tempalte takes 20mn to
compile, your template design is wrong ... In our own HPC template base
code, everything compiles under 20s and only some exhaustive unti test
that instanciate all and every type/functiosn took up to 5mn.
> 2) Current compilers may not even be able to compile large amounts of template code at all. There are compilers that we have to support (e.g. Sun and IBM) that will segfault or return "internal compiler error" when you give them too much template code. These same compilers have no problem with virtual functions with standard OO. This is reality.
>
Sun and IBM are all but references on the point of tempalte handling ...
gcc, MSVC, ICC and even clang don't choke on most templated code ...
What about stopping working with compilers from before the industrial
revolution ?

> 3) Templated programs can result in massive object-code bloat over equivalent runtime OO programs. If you are really sloppy with templates and use it for everything, you can easily double, triple, or more (10x) the size of the object code and executables (see Item 44 in "Effective C++, 3ed edition").
>
>
same than 1/ learn to do it right ... And well, since when gigabyte
started to be costly ?

> 4) The error messages you get when mistakes are made when using explicit interfaces and virtual functions are far superior to the mess that most compliers put out when you make a mistake with implicit compile-time template interfaces. This is a huge issue. Runtime errors, as opposed to cryptic compile-time errors, can be handled by throwing exceptions with very good error messages that programmers can 100% control the quality of. Yes, of course you prefer compile-time errors to runtime errors all things being equal, and am not arguing to prefer runtime errors over compile-time errors in general. This is generally not true of template programming (there are some tricks you can use to improve compile-time error messages, but not perfectly). For example, if you make a mistake with STL iterators/algorithms you can get very cryptic error messages that dumfound most (non-expert and expert) C++ programmers.
>
Use SFINAE, Concept Checks and static assert ...
> 5) Well written OO C++ software allows for significant runtime flexibility. If you use dynamic libraries, for instance, you can add new implementations of objects without even having to relink customer executables. Also, you can fix many types of bugs in updated shared libraries without having to recompile/relink customer executables. In a large-scale software setting, this can be very helpful.
>
That's maybe th eonyl poitn where I agree with you.
> ********************************************************************************************
> *** You can't portably compile and link large C++ programs that template everything!!!!! ***
> ********************************************************************************************
>
Why ?
> As long as people keep suggesting that we template all of our codes for every little reason, I am going to keep reminding people of the realities of template code in C++. If you can't respond to the above points (especially #1 and #2) then there is little point in continuing the discussion. Thinking that we are going to drop runtime polymorphism and use exclusively compile-time polymorphism for everything is just fantasy land.
>
Nobody told you to put template everywhere. Same we don't want to put
dynamic polymorphism everywhere. What about learnign to sue the proper
tool for the proper task ?


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