www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: The Next Big Language

reply bearophile <bearophileHUGS lycos.com> writes:
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).

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-u ing-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
Oct 19 2010
next sibling parent dennis luehring <dl.soluz gmx.net> writes:
Am 19.10.2010 13:29, schrieb bearophile:
 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-u
ing-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.

and that generates a very bad scenario for "templates" because if you find (as an newbie) a small and understandable template code example -> these code normaly don't show the potential behind templates/generics... and if you see code that realy profits from using templates/generics you can't see the profit because its hidden under masses of C++ evil syntax orgies
Oct 19 2010
prev sibling parent Justin Johansson <no spam.com> writes:
On 19/10/2010 10:29 PM, bearophile wrote:
 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).

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-u ing-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

You are a smart person bearophile, much smarter than me. Cheers, Justin
Oct 19 2010