Why the @ in @safe? & UDAs

Jonathan M Davis jmdavisProg at gmx.com
Thu Nov 7 12:16:34 PST 2013


On Thursday, November 07, 2013 21:00:08 Benjamin Thaut wrote:
> Am 07.11.2013 16:55, schrieb Jonathan M Davis:
> > On Thursday, November 07, 2013 07:07:44 Benjamin Thaut wrote:
> >> What about gaining consitency? That was something D1 was really strong
> >> in, but D2 lost.
> > 
> > Then should public and private be @public and @private in order to be
> > consistent? Then we'd be inconsistent with C++, Java, C# etc. which would
> > make it that much harder for folks to learn D. Would you want @static and
> > @const?
> > 
> > I don't think that you can be 100% consistent. If nothing else, as soon as
> > you make one thing consistent, it often ends up being inconsistent with
> > something else. And sometimes consistency costs us. For instance, this is
> > perfectly legal
> > 
> > const Object foo();
> > 
> > and is equivalent to
> > 
> > Object foo() const;
> > 
> > because that's the way it is for every other attribute, but it's a source
> > of confusion and bugs, because most everyone seems to expect that
> > 
> > const Object foo();
> > 
> > would be equivalent to
> > 
> > const(Object) foo();
> > 
> > I understand why it would be desirable to try and make all of the
> > attributes consistent, and if we were starting from scratch or were
> > fairly early along in language development, then I'd be in favor of it.
> > But we're way too far along at this point IMHO. The only practical
> > benefit to making such changes now would be to try and make the language
> > easier for newcomers - which is a laudible goal to be sure, but I don't
> > think that the cost of having to know that it's @safe, @trusted, and
> > @system whereas ever other language-defined attribute lacks @ is
> > particularly high - particularly when the cost of fixing it is breaking
> > pretty much every D program in existence. It's just a small quirk that
> > you have to learn, and then it's not really a problem anymore.
> > 
> > The benefits of such a change would be almost purely aesthetic, and it
> > would break _everyone_'s code without adding any practical benefit
> > whatsoever.
> > 
> > I'm probably the person who's broken the most code due to making changes
> > to
> > Phobos in order to make its symbol names consistent, so I'm definitely in
> > favor of making the language and its libraries consistent and see value
> > in that, but I think that we're past the point where we can afford such
> > breaking changes (and this suggested change would break far more than any
> > change to Phobos ever has). We need to be stable, or no one is going to
> > use D. And breaking every D program in existence over an aesthetic issue
> > is just going to harm our reputation in that regard. We finally seem to
> > be starting to shake off the reputation for breaking code that we've had,
> > and our stability continues to increase. We don't want to turn around and
> > make such a large breaking change for aesthetic reasons. That would not
> > only tick off the majority of our existing user base, but it would scare
> > away many of the newbies that this change would be supposed to help.
> > 
> > - Jonathan M Davis
> 
> Well if you ask me builtin attributes should not have the '@' so that
> only UDAs start with '@'.
> 
> I don't think that we are past the point of making breaking changes. the
> D user base it not that big. And those that are here are already used to
> stuff constantly breaking, otherwise they would be gone already. Also no
> one said they should be breaking right away. We can slowly deprecate
> them or at least provide both versions, so there is at least the option
> to make the D code consistent.

With regards to the cost/benefit ratio, such a change fails miserably. This is 
exactly the sort of change that Walter and Andrei were talking about stopping 
completely at dconf, precisely because it doesn't actually fix anything. 
Breaking changes need to provide real, tangible benefits which are greater than 
the cost that they incur. And while I tend to agree that it would be better 
had none of the built-in attributes used @, changing it won't fix any bugs and 
won't make any software easier to mantain save perhaps for a tool which 
lexes/parses the language, and handling the few built-in attributes with @ is 
trivial in that case. The benefits are aesthetic, and changing it requires 
changing pretty much all existing D code. And even if you can avoid having the 
change break code immediately, it still requires changing the code, so it's 
not like that eliminates the cost of the change. It just spreads it out.

If you want anything like this to happen, you'll have to convince Walter and 
Andrei, and I would be shocked if they were ever convinced. They want to focus 
on stability, not on tweaking everything in search of making the language 
perfect. Breaking changes - especially breaking changes on this scale - need 
to provide real, tangible benefits which outweigh the cost of the breakage. And 
changing the @ attributes doesn't even come close.

- Jonathan M Davis


More information about the Digitalmars-d mailing list