Jump to page: 1 2 3
Thread overview
FAQ for newbies who see pure @safe nothrow @nogc
Jan 28, 2015
Jonathan Marler
Jan 29, 2015
Jesse Phillips
Jan 29, 2015
deadalnix
Jan 29, 2015
Jonathan Marler
Jan 29, 2015
matovitch
Jan 29, 2015
matovitch
Jan 29, 2015
matovitch
Jan 29, 2015
Jonathan Marler
Jan 29, 2015
matovitch
Jan 29, 2015
Jonathan Marler
Jan 29, 2015
matovitch
Jan 29, 2015
Jonathan Marler
Jan 29, 2015
matovitch
Jan 29, 2015
Nick Treleaven
Jan 29, 2015
matovitch
Jan 29, 2015
Jonathan Marler
Jan 29, 2015
Jonathan Marler
Jan 29, 2015
deadalnix
Jan 29, 2015
Jonathan Marler
Jan 29, 2015
matovitch
Jan 29, 2015
matovitch
Jan 29, 2015
deadalnix
Jan 30, 2015
Nick Treleaven
January 28, 2015
I believe we have reached consensus in our discussion about how to solve the issues of having some function attributes use a '@' and some not.

void foo() pure @safe nothrow @nogc;

I'd like to put the following question/answers somewhere that we can point newbies to so that when someone asks again, the discussion can be quenched immediately by simply directing them to the FAQ.  Maybe that means we link them to this post, maybe it means we add it to the site somewhere.  Feel free to improve.  Here they are:

Why do some function attributes have a '@' and some dont?
-----------------------------------------------------------

Simple answer, "Words that are considered "keywords" don't require a '@', and non-keywords do".  A list of keywords is found here http://dlang.org/lex.html#Keyword.  This includes pure and nothrow, but does not include safe or nogc.

Why don't we make all the function attributes keywords?
-----------------------------------------------------------

A keyword cannot be an identifier. Since 'int' is a keyword, it cannot be used as a variable name, function name, etc. Because of this, if you add a new keyword, any code that was using that keyword before is now broken.  As D matures more keywords may be added but we are also trying to figure out the best set of function attributes. Instead of adding and removing keywords all the time, we use the '@' symbol until it becomes clear the new word should be a keyword.

Why do we have to use a '@' if the word is not a keyword?
-----------------------------------------------------------

It's possible to allow words to be function attributes that are not keywords, however, the D leadership feels that having a word serve as a function attribute in one context and an identifier in another is bad.
January 29, 2015
It would be somewhere under:
http://wiki.dlang.org/

Maybe Documentation => Language Design Explanation?
January 29, 2015
On Thursday, 29 January 2015 at 04:16:30 UTC, Jesse Phillips wrote:
> It would be somewhere under:
> http://wiki.dlang.org/
>
> Maybe Documentation => Language Design Explanation?

Yes, that is a clear sum up of the discussion.
January 29, 2015
On Wednesday, 28 January 2015 at 22:32:55 UTC, Jonathan Marler wrote:
>
> Why don't we make all the function attributes keywords?
> -----------------------------------------------------------

As a newbie, I would have asked the reversed question :

Why don't we make all the function attributes attributes?
January 29, 2015
On Thursday, 29 January 2015 at 10:34:37 UTC, matovitch wrote:
> On Wednesday, 28 January 2015 at 22:32:55 UTC, Jonathan Marler wrote:
>>
>> Why don't we make all the function attributes keywords?
>> -----------------------------------------------------------
>
> As a newbie, I would have asked the reversed question :
>
> Why don't we make all the function attributes attributes?

To be clear, what are the avantages of keywords vs attributes ? Why should the most used function attributes be keywords ?
January 29, 2015
On Thursday, 29 January 2015 at 10:38:46 UTC, matovitch wrote:
> On Thursday, 29 January 2015 at 10:34:37 UTC, matovitch wrote:
>> On Wednesday, 28 January 2015 at 22:32:55 UTC, Jonathan Marler wrote:
>>>
>>> Why don't we make all the function attributes keywords?
>>> -----------------------------------------------------------
>>
>> As a newbie, I would have asked the reversed question :
>>
>> Why don't we make all the function attributes attributes?
>
> To be clear, what are the avantages of keywords vs attributes ? Why should the most used function attributes be keywords ?

"In theory, the increased consistency is welcome, but the increased visual
noise definitely is not.  And if we leave in pure and nothrow without @,
then we're going to have code out there doing both, which adds to the
confusion, and if we deprecate pure and nothrow without @, then we'll be
forced to change pretty much every D program in existence." JM Davis

Ok !
January 29, 2015
On Thursday, 29 January 2015 at 04:16:30 UTC, Jesse Phillips wrote:
> It would be somewhere under:
> http://wiki.dlang.org/
>
> Maybe Documentation => Language Design Explanation?

Anyone else "for" or "against" this?  If no one protests I can create it, along with the FAQ from matovich and including Walters extra explanation about increasing redundancy.
January 29, 2015
On Thursday, 29 January 2015 at 10:43:37 UTC, matovitch wrote:
> On Thursday, 29 January 2015 at 10:38:46 UTC, matovitch wrote:
>> On Thursday, 29 January 2015 at 10:34:37 UTC, matovitch wrote:
>>> On Wednesday, 28 January 2015 at 22:32:55 UTC, Jonathan Marler wrote:
>>>>
>>>> Why don't we make all the function attributes keywords?
>>>> -----------------------------------------------------------
>>>
>>> As a newbie, I would have asked the reversed question :
>>>
>>> Why don't we make all the function attributes attributes?
>>
>> To be clear, what are the avantages of keywords vs attributes ? Why should the most used function attributes be keywords ?
>
> "In theory, the increased consistency is welcome, but the increased visual
> noise definitely is not.  And if we leave in pure and nothrow without @,
> then we're going to have code out there doing both, which adds to the
> confusion, and if we deprecate pure and nothrow without @, then we'll be
> forced to change pretty much every D program in existence." JM Davis
>
> Ok !

I'm not sure I understand your question.

Why don't we make all the function attributes attributes?

Is this what you mean? "Why don't we require an '@' symbol before all function attributes?"


January 29, 2015
On Thursday, 29 January 2015 at 15:10:12 UTC, Jonathan Marler wrote:
> On Thursday, 29 January 2015 at 10:43:37 UTC, matovitch wrote:
>> On Thursday, 29 January 2015 at 10:38:46 UTC, matovitch wrote:
>>> On Thursday, 29 January 2015 at 10:34:37 UTC, matovitch wrote:
>>>> On Wednesday, 28 January 2015 at 22:32:55 UTC, Jonathan Marler wrote:
>>>>>
>>>>> Why don't we make all the function attributes keywords?
>>>>> -----------------------------------------------------------
>>>>
>>>> As a newbie, I would have asked the reversed question :
>>>>
>>>> Why don't we make all the function attributes attributes?
>>>
>>> To be clear, what are the avantages of keywords vs attributes ? Why should the most used function attributes be keywords ?
>>
>> "In theory, the increased consistency is welcome, but the increased visual
>> noise definitely is not.  And if we leave in pure and nothrow without @,
>> then we're going to have code out there doing both, which adds to the
>> confusion, and if we deprecate pure and nothrow without @, then we'll be
>> forced to change pretty much every D program in existence." JM Davis
>>
>> Ok !
>
> I'm not sure I understand your question.
>
> Why don't we make all the function attributes attributes?
>
> Is this what you mean? "Why don't we require an '@' symbol before all function attributes?"

Yes, if @ttributes are better because you can create identifier with the same name why aren't they used everywhere ? By the way, the denomination makes sense too : function attibutes are either built-in or user defined attributes. But const can be a qualifier or a function/method attribute that is two very different things...maybe not beeing able to use const as a function attribute but @const would make more sense ?
January 29, 2015
On Thursday, 29 January 2015 at 15:39:18 UTC, matovitch wrote:
> Yes, if @ttributes are better because you can create identifier with the same name why aren't they used everywhere ? By the way, the denomination makes sense too : function attibutes are either built-in or user defined attributes. But const can be a qualifier or a function/method attribute that is two very different things...maybe not beeing able to use const as a function attribute but @const would make more sense ?

The purpose of this thread wasn't to re-discuss what was already discussed.  The answer to your idea can be found in the other thread http://forum.dlang.org/post/rtwbtxigfeupvykpbamh@forum.dlang.org.  It's gonna be a long read so I'll summarize what I believe is the correct answer.

The problem we are trying to solve is that the function attributes are inconsistent.  Some use @ like "@safe" and "@nogc" and some don't like "pure" and "nothrow".

So one idea is to require an '@' symbol in front of all of them for the sake of consistency.  The problem with this idea is that you've now introduced inconsistency somewhere else.  Every keyword that you put an '@' symbol in front of, will be used somewhere else without an '@' symbol.  Like this:

abstract class MyClass { }
@abstract void myfunc();

See the inconsistency?  You're gonna end up with alot of these types of inconsistencies. In addition, you've made the rule of when to use the '@' symbol more complex.  Before it was, "Use '@' if it is not a keyword".  Now it's, "Use '@' if it is not a keyword except when it's a function attribute".  This definition will likely be made worse since people will want to solve the newly introduced inconsistencies.  So the new definition will become, "Use '@' if it is a keyword except if it's a function attribute or a class specifier".  By the time you solve every inconsistency you'll have made every usage of every keyword use the '@' symbol.  Then the rule will be "Always use the '@' symbol".

This will definitely be included on the FAQ :)  I'll reword it and modify it but I agree that people will want an explanation for this.
« First   ‹ Prev
1 2 3