Does D have too many features?
H. S. Teoh
hsteoh at quickfur.ath.cx
Sun Apr 29 08:17:56 PDT 2012
On Sun, Apr 29, 2012 at 02:35:07AM -0400, Nick Sabalausky wrote:
> "Timon Gehr" <timon.gehr at gmx.ch> wrote in message
> news:jnhpvv$ih4$1 at digitalmars.com...
[...]
> > Implementing a compiler is probably harder for D, because of the
> > interplay of forward references, CTFE and compile time
> > introspection.
>
> Those make D more difficult to implement than many languages, but
> OTOH, AIUI, C++ has some real nightmarish details with templates and
> even just simply parsing. Probably some other bizarre cruft, too.
> IIRC, I think Walter's occasionally mentioned something about
> the...overload rules?
[...]
It has been said that C++ cannot be lexed before it's parsed. Before
C++11, for example, this is invalid:
std::vector<std::vector<T>> nestedList;
Instead, you have to write:
std::vector<std::vector<T> > nestedList;
Fortunately they fixed this in C++11. But now you have another problem:
std::vector<myTemplate<T>>1> nestedList;
Whether or not this is valid depends on whether T is a type name or a
variable name (e.g., if myTemplate takes an int parameter). But how is
the lexer even supposed to know whether the >> should be a right shift
operator or two right angle brackets? It has to understand the
_semantics_ of T before it can even lex the thing.
I read somewhere that one of D's goals was to be able to lex the
language without requiring semantic knowledge in the lexer. You have no
idea how much such a seemingly-obvious concept can save hours, days,
nay, months and years of frustration in compiler implementation.
So you think D is hard to implement? We have barely even begun to delve
into the insane convolutions of C++. You'll start to have some real
hair-tearing sessions once you start getting into implicit conversion
rules and template best-match algorithms. Be glad, be very glad that we
have D instead of C++!
T
--
Designer clothes: how to cover less by paying more.
More information about the Digitalmars-d
mailing list