Oh Dear
Michiel Helvensteijn
m.helvensteijn.remove at gmail.com
Sat Jul 11 14:05:32 PDT 2009
Walter Bright wrote:
>> I believe that what D really needs is a complete formal specification of
>> the language grammar and semantics. Last I heard, there wasn't any.
>
> There is a specification. It isn't complete and there are bugs in it,
> but it constantly gets worked on to improve it. Anyone can submit
> improvements on it to bugzilla.
>
> The lack of a 100% specification has never hindered any language I can
> think of from attaining wide use. What mattered there was that the
> language solved the problems that needed solving.
I'm not sure. You may be right.
But in my opinion, the language specification should define the language,
whereas any single compiler should merely implement it. It looks like D
works the other way around.
The D website offers a reference manual for the general workings of D. It
gives examples. Most of it is explained clearly. But it's not a formal
specification. Words are very imprecise.
For example, from the MulExpression sections of D (1.0 and 2.0):
----------
For integral operands, the *, /, and % correspond to multiply, divide,
and modulus operations. For multiply, overflows are ignored and simply
chopped to fit into the integral type. If the right operand of divide or
modulus operators is 0, an Exception is thrown.
----------
What does "chopped to fit the integral type" mean? What if it's a
multiplication between two differently sized integral types?
And how does D handle integer division when one or both of the operands are
negative? Does it use truncated division, Euclidean division, floored
division? I can't tell by the modulo operator, since it is implementation
defined for negative operands (which seems like a strange decision, since
this makes modulo utterly unreliable in those cases).
---------- (continued)
For integral operands of the % operator, the sign of the result is
positive if the operands are positive, otherwise the sign of the result is
implementation defined.
----------
I believe you want "non-negative" there.
See what I mean? When you get down to the details, the reader is left
guessing, because formal semantics should be given in math, not in English.
That's how compiler writers know how to implement their compiler.
I can understand that when you start designing a programming language, you
write the compiler and document the language from there. But I believe a
language as far along as D should not be working that way anymore.
--
Michiel Helvensteijn
More information about the Digitalmars-d
mailing list