The Wrong Stuff
Jonathan M Davis
jmdavisProg at gmx.com
Sat Sep 25 08:53:52 PDT 2010
On Saturday 25 September 2010 06:11:25 Michel Fortin wrote:
> On 2010-09-25 08:23:52 -0400, "Simen kjaeraas" <simen.kjaras at gmail.com> said:
> > A rose by any other name...
> >
> > You may label them whatever you want. The fact still is - built-in
> > @tributes are reserved words of the language, with special meaning to
> > the compiler. If that is not a keyword, I would like to hear a
> > common definition of keyword that does not include @tributes, and a
> > definition of what @tributes are in comparison.
>
> Just to add to your point: Objective-C is an extension of C that
> defines a few more keywords too. Most of which are prefixed with @ so
> they don't conflict with anything, yet they're said to be keywords. I
> concur with Simen: this "attribute" vs. "keyword" thing is just a
> naming convention.
>
> The D community has chosen to call "attributes" the keywords that are
> prefixed by @ in an attempt to "reduce" the number of keywords (because
> some have criticized the increasing number of keywords). True, those
> "attribute-style keywords" don't take more identifiers as reserved
> words. But if you dig a little in the DMD source, you'll see there is
> no difference in how these attributes and other keywords are processed
> once you have passed the parsing stage, they just become flags on data
> structures, just like regular keywords often do.
There is a distinct difference between keywords and attributes, but it's
certainly true that attributes at this point don't have much semantic difference.
The real difference is in the grammar. The fact that you can write a program like
this
void main()
{
int property = 7;
}
is because property is not a keyword. Keywords are specifically words reserved by
the compiler and cannot be used as identifiers. What they actually do is
irrelevant (heck, goto and const are keywords in Java that aren't used for
*anything* - they're just reserved, so you can't use them). Properties don't
fall in that category at all, regardless of how they're used semantically, so
they definitely aren't keywords. Attributes make a lot more sense when you look
at a language like Java which allows for user-defined attributes. At the moment,
they only really act as type modifiers similar to pure or static, so they don't
end up being particularly different from type modifiers which are keywords. Still,
they aren't keywords.
> And to make the matter worse, most attributes are not @attributes [1].
> We have a concept of @attribute at the syntactic level, and another
> totally different concept of attribute at the semantic level.
>
> [1]: http://www.digitalmars.com/d/2.0/attribute.html
>
> At this stage I've lost all hopes of coherency in that part of the
> language. To me, the explanation to differentiate the two is quite
> simple: an historical incident made all new keywords added after a
> certain date use the @attribute syntax.
Even Java has that sort of problem, though differently. For instance,
Serialiazable is an interface - which has nothing in it. It just says that that
class is allowed to be serialized. It really should be an attribute, but it was
put in the language before attributes were.
As for D, arguably pretty much any modifier really should be an attribute, but
that wouldn't be following what C++, Java, C#, etc have done with static,
private, etc. So, anything that is in any of those languages as a keyword is a
keyword in D rather than an attribute. That alone makes it so that attributes
and modifiers which are keywords will never be consistent. But it's not even
consistent with the stuff that D added as to whether it's an attribute or a
keyword - pure being a prime example (nothrow at least has the excuse of throws
being used in essentially the same context in other languages). Ultimately, it
does pretty much come across as later stuff being made into attributes rather
than keywords with no overriding principle behind it. But unless we want to
break convention with other languages, I don't think that there's much hope of
making it consistent anyway. You'd have to make a lot of stuff attributes instead
of keywords which would throw people off (like static, public, abstract, etc.)
and make it more work to port code.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list