foreach and metaprogramming
Per Eckerdal
per.eckerdal at gmail.com
Tue Nov 7 14:24:59 PST 2006
I have spent some time reading the archives of these newsgroups, and
I've seen quite a lot, especially on dtl about foreach and
foreach_reverse and how they should be designed to support that-and-that
feature. And there are a lot of other places where people talk about
"2.0" features.
Just my 2 cents about this:
A language should not strive to have many features, but rather a small
set of features that allow you to do other things on top of it. (Yes,
I'm one of those scary lisp guys.) If you add tools to create your own
statements then you don't need to have foreach or foreach_reverse.
I don't know very much about how compilers work when optimizing but I
can't see how foreach to a for loop would reduce performance.
I don't know if OpenC++/OpenJava
(http://www.csg.is.titech.ac.jp/openjava/) work well, but that's pretty
much the idea. I've seen that someone has already tried to do this in D,
but I think it deserves more attention.
Now this is _definitely_ a 2.0 feature :), but still, wouldn't it be
cool to remove the need for static if, foreach, synchronized and
contract programming and replace it with something even more general,
that also lets you do cool stuff like compile-time generation of
serialization functions, reflection/introspection/rtti implemented in
the language.. The list goes on.
To me the question seems to be whether to implement one feature after
another and inevitably seeing D become bloated like all the other
languages (Java, C++) or implementing a metaobject protocol and have all
those features in a snap and being able to extend the language beyond
Java's wildest dreams, without bloating the core language. (Okay, I
admit that was slightly angled towards my view, but I hope you get my point)
Don't think I dislike D, I am seriously impressed by it and like it a
lot. I just think it could be even better :)
/Per
More information about the Digitalmars-d
mailing list