The Next Big Language

bearophile bearophileHUGS at lycos.com
Tue Oct 19 04:29:29 PDT 2010


Justin Johansson

>There is also a big problem with reconciling templated types with OO typed hierarchies.  Often a dichotomy appears when templates and classes seem to fight one another when you try to marriage the two idioms together (for better or for worse but generally worse). :-(<

Right.

-------------

Peter Alexander:

>I think it has very little to do with the syntax (although it certainly plays a part).
The real problem with templates (in my opinion) is that they require a higher level abstract view of programs that most programmers simply lack. I think this is the same reason why functional programming escapes the masses, and why C is still so popular.<

Some of the problems of C++ templates:
- The syntax is a big problem; if you want to use them to do complex things you need to write lot of ugly code. The lack of basic constructs like static if doesn't help at all.
- The semantics is not clean, there are several corner cases, that turn template programming into a puzzle solving activity.
- C++ templates are a functional language, but the C++ compilers usually lacks the normal tools a functional language needs, like a garbage collector and an optimizer both designed for a functional language, and error messages good for a functional language. This makes then slow for the compiler, and at compile-time the compiler burns lot of RAM (they have improved a bit G++ 4.5, as template instantiations are now looked up using hash tables: http://cpptruths.blogspot.com/2010/03/faster-meta-programs-using-gcc-45-and.html  but it's a long way to go).
- C++ templates are powerful, because templates templates are a peek into the realm of higher order types (kinds), but there is not much typing on the types, so bugs are common. The Concepts were a way to add a type system to template arguments, but it has failed.
- C++ programmers sometimes don't know much about functional programming. But in the end the complexity of functional programs written with C++ templates is very limited, they are often almost trivial. What makes them hard to write is not that, it's the way you have to write such little functional programs.

D2 improves the situation a bit (with constraints, a more consistant semantics, a bit better syntax, static ifs, more template argument types, and some shortcuts), but there's a long way to go still. Despite the constraints D templates are still "dynamically kinded" (the enforcement is one way only, not two way as in the Concepts, you may solve the problem a bit manually, as Andrei has shown me), the compile-time GC is not good enough yet, lot of useless stuff is left in the final binaries, etc.

D2 templates too may cause bloat, because there is no way to choose where you want Java or C# style generics with auto-boxing and where you want C++-style templates (this may be good anyway, to keep both language and compiler simpler).

Bye,
bearophile


More information about the Digitalmars-d mailing list