July 22, 2004
Stephen Waits wrote:
> Norbert Nemec wrote:
>> Stephen Waits wrote:
>> 
>>>The thing about it is.. C++ template expressions are a nasty ugly hack.
>> 
>> This is not quite right. It is true, that meta-programming in C++ is a dirty business. But so far, I know of no other language (except a few experimental ones that never made it out into the real world) that offers a similar functionality. I agree, that in C++, the syntax and a few details are designed suboptimal, but I doubt that the core idea of expression templates can be captured by a simpler technique.
> 
> I think I'm correct in saying that it's a "nasty ugly hack".  However, I agree, the functionality has yet to be reproduced in a language other than C++.
> 
> My idea is that, given what we've learned with C++ in the past decade, perhaps now we can achieve the same functionality, without it being a "nasty ugly hack".  Think it's possible?  Or am I overly optimistic?

First, we should try to identify what makes expression templates so ugly in C++. I think, the basic concept of them should be kept in D. It certainly is not a simple concept, but meta-programming just is an advanced subject, so one should not hope for a simple solution.

The problem therefore are not the expression templates, but more fundamental: the meta-language in C++. Looking closely, this meta-language is a purely functional language which is executed at compile-time. It handles types and constant values. The "functions" of this language are the templates (taking types and constants as parameters and "returning" types and constants through the content that can be accessed from outside)

The problem in C++ is this language, which was actually found by accident and which is ugly to program, ugly to debug and inefficient to execute (resulting in extremely long compile times for et-programs)

What we can do in D is to try to improve and clean up this language. Most of it is already given by the mechanism of templates. The concept already is very similar to that of C++, so it is too late already for going completely different direction, but there is still a lot of room left for improvement. A few ideas:

* allowing function calls in constant expressions (restricted to pure functions with only constant arguments) - the compiler would have to be able to identify pure functions (no side-effects, no access to anything besides the arguments) but that should be possible without changes to the language.

* compile-time flow control - basically, a compile-time "if" extending the idea of "version", it should take any constant boolean argument, be allowed outside of functions and not open a new namespace.

* string handling at compile time

* identifier <-> string <-> integer conversion at compile-time

* maybe most advanced: "list"-handling at compile time

Anyhow, all of this is, of course far beyond 1.0 ...


1 2
Next ›   Last »