Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 23, 2011 "body" keyword is unnecessary | ||||
---|---|---|---|---|
| ||||
D already has a long list of keywords, reserved words can't be used as identifiers, which can be annoying. "body" in particular is a common noun that programmers would gladly use as a variable name in physics simulation, astronomy, mechanics, games, health, etc. I think "body" can be removed from D with no harm, and with the benefit of allowing the name as identifier. Rationale: Functions in C and derived languages have always had a body and they never needed a keyword. In D, "body" is used to mark the actual body of a function after the optional "in" and/or "out" contract blocks. What is different in the body itself of a function with and without contracts to make one body{...} and the other {...}? Example: int myfunc(int x) in{ ...contract preconditions... } out (result){ ...contract postconditions... } body{ ...code... } But we don't write: int myfunc(int x) body{ ...code... } The body keyword can be omitted and still interpret the code correctly given this rule: "An unnamed {...} block right after an in{} or out{} block when defining a function, MUST be the function's body". Thus, the above code would become: int myfunc(int x) in{ ...contract preconditions... } out (result){ ...contract postconditions... } { ...code... } and be perfectly understandable, with the benefit of one less keyword. The compiler, upon reading the opening "{" after the out block, would know it is the beginning of the function body. Or I am missing something that would overcomplicate parsing, etc? Best regards |
March 23, 2011 Re: "body" keyword is unnecessary | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alvaro | Yep, this has been brought up at least once before. Nothing has happened so far. |
March 24, 2011 Re: "body" keyword is unnecessary | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alvaro | Interestingly, you don't even have to remove "body" from the syntax to remove it as a keyword, as it's only used in this context (that I know of), where no other symbols make sense. |
March 24, 2011 Re: "body" keyword is unnecessary | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alvaro | I'm all for this change. Since there are already similar differences between 1.0 and 2.0 (e.g. invariant()) and projects can be fixed by a more or less simple search and replace, this would be a cheap way to clean up a keyword that can truly get in your way (in contrast to some others that have already been removed). Actually I think the only keywords that really got in my way were "body" and "function" - I now have modules named body_.d and function_.d |
March 24, 2011 Re: "body" keyword is unnecessary | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alvaro | On Wed, 23 Mar 2011 23:17:32 +0100, Alvaro wrote:
> D already has a long list of keywords, reserved words can't be used as identifiers, which can be annoying. "body" in particular is a common noun that programmers would gladly use as a variable name in physics simulation, astronomy, mechanics, games, health, etc. I think "body" can be removed from D with no harm, and with the benefit of allowing the name as identifier.
yes, please
body is also a html tag
Cheers
Piotrek
|
March 24, 2011 Re: "body" keyword is unnecessary | ||||
---|---|---|---|---|
| ||||
Posted in reply to piotrek | == Quote from piotrek (starpit@tlen.pl)'s article
> On Wed, 23 Mar 2011 23:17:32 +0100, Alvaro wrote:
> > D already has a long list of keywords, reserved words can't be used as identifiers, which can be annoying. "body" in particular is a common noun that programmers would gladly use as a variable name in physics simulation, astronomy, mechanics, games, health, etc. I think "body" can be removed from D with no harm, and with the benefit of allowing the name as identifier.
> yes, please
> body is also a html tag
> Cheers
> Piotrek
Copied the following line from the Vala (=mostly reference counted language) web page.
"It is possible to use a reserved keyword as identifier name by prefixing it with the @ character. This character is not part of the name. For example, you can name a method foreach by writing @foreach, even though this is a reserved Vala keyword."
My body is hungry and starving.
|
March 24, 2011 Re: "body" keyword is unnecessary | ||||
---|---|---|---|---|
| ||||
Posted in reply to sclytrack | sclytrack: > Copied the following line from the Vala (=mostly reference counted language) web page. > > "It is possible to use a reserved keyword as identifier name by prefixing it with the @ character. This character is not part of the name. For example, you can name a method foreach by writing @foreach, even though this is a reserved Vala keyword." In C# there is the same thing: >The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier. Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style.< http://msdn.microsoft.com/en-us/library/aa664670%28v=vs.71%29.aspx Bye, bearophile |
March 24, 2011 Re: "body" keyword is unnecessary | ||||
---|---|---|---|---|
| ||||
Posted in reply to sclytrack | On Mar 24, 11 19:00, sclytrack wrote:
> == Quote from piotrek (starpit@tlen.pl)'s article
>> On Wed, 23 Mar 2011 23:17:32 +0100, Alvaro wrote:
>>> D already has a long list of keywords, reserved words can't be used as
>>> identifiers, which can be annoying. "body" in particular is a common
>>> noun that programmers would gladly use as a variable name in physics
>>> simulation, astronomy, mechanics, games, health, etc. I think "body" can
>>> be removed from D with no harm, and with the benefit of allowing the
>>> name as identifier.
>> yes, please
>> body is also a html tag
>> Cheers
>> Piotrek
>
> Copied the following line from the Vala (=mostly reference counted language) web page.
>
> "It is possible to use a reserved keyword as identifier name by prefixing it with
> the @ character. This character is not part of the name. For example, you can name
> a method foreach by writing @foreach, even though this is a reserved Vala keyword."
>
> My body is hungry and starving.
>
>
How is this better than _body or body_?
|
March 24, 2011 Re: "body" keyword is unnecessary | ||||
---|---|---|---|---|
| ||||
Posted in reply to KennyTM~ | On Thu, 24 Mar 2011 21:37:12 +0800, KennyTM~ wrote:
> On Mar 24, 11 19:00, sclytrack wrote:
>> == Quote from piotrek (starpit@tlen.pl)'s article
>>> On Wed, 23 Mar 2011 23:17:32 +0100, Alvaro wrote:
>>>> D already has a long list of keywords, reserved words can't be used as identifiers, which can be annoying. "body" in particular is a common noun that programmers would gladly use as a variable name in physics simulation, astronomy, mechanics, games, health, etc. I think "body" can be removed from D with no harm, and with the benefit of allowing the name as identifier.
>>> yes, please
>>> body is also a html tag
>>> Cheers
>>> Piotrek
>>
>> Copied the following line from the Vala (=mostly reference counted
>> language) web page.
>>
>> "It is possible to use a reserved keyword as identifier name by prefixing it with the @ character. This character is not part of the name. For example, you can name a method foreach by writing @foreach, even though this is a reserved Vala keyword."
>>
>> My body is hungry and starving.
>>
>>
>>
> How is this better than _body or body_?
I think "@" is a little bit nicer, but it doesn't change the situation at all . body (if possible) shouldn't be a keyword.
Can anyone from the steering group state his opinion? :)
Cheers,
Piotrek
|
March 24, 2011 Re: "body" keyword is unnecessary | ||||
---|---|---|---|---|
| ||||
Posted in reply to piotrek | piotrek wrote:
> On Thu, 24 Mar 2011 21:37:12 +0800, KennyTM~ wrote:
>
>> On Mar 24, 11 19:00, sclytrack wrote:
>>> == Quote from piotrek (starpit@tlen.pl)'s article
>>>> On Wed, 23 Mar 2011 23:17:32 +0100, Alvaro wrote:
>>>>> D already has a long list of keywords, reserved words can't be used
>>>>> as identifiers, which can be annoying. "body" in particular is a
>>>>> common noun that programmers would gladly use as a variable name in
>>>>> physics simulation, astronomy, mechanics, games, health, etc. I think
>>>>> "body" can be removed from D with no harm, and with the benefit of
>>>>> allowing the name as identifier.
>>>> yes, please
>>>> body is also a html tag
>>>> Cheers
>>>> Piotrek
>>> Copied the following line from the Vala (=mostly reference counted
>>> language) web page.
>>>
>>> "It is possible to use a reserved keyword as identifier name by
>>> prefixing it with the @ character. This character is not part of the
>>> name. For example, you can name a method foreach by writing @foreach,
>>> even though this is a reserved Vala keyword."
>>>
>>> My body is hungry and starving.
>>>
>>>
>>>
>> How is this better than _body or body_?
>
> I think "@" is a little bit nicer, but it doesn't change the situation at all . body (if possible) shouldn't be a keyword.
> Can anyone from the steering group state his opinion? :)
What's the steering group?
I raised this exact topic before, with the title "my body is ugly" <g>.
It's a very silly keyword. It's just a comment, really /*body*/.
|
Copyright © 1999-2021 by the D Language Foundation