Bug 5775 – "body" keyword is unnecessary

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-03-23T14:46:00Z
Last change time
2012-01-20T19:00:36Z
Assigned to
nobody
Creator
alvaro.segura

Comments

Comment #0 by alvaro.segura — 2011-03-23T14:46:55Z
D already has a long list of keywords, and those reserved words can't be used as identifiers. "body" in particular is a common noun that programmers would gladly use as 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. From the documentation: in{ ...contract preconditions... } out (result){ ...contract postconditions... } body{ ...code... } But the body keyword can be omitted and still interpret the code correctly given the 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: in{ ...contract preconditions... } out (result){ ...contract postconditions... } { ...code... } and be perfectly understandable, with the benefit of one less keyword.
Comment #1 by bearophile_hugs — 2011-03-23T15:43:22Z
Considering the strong resistance against adding new kewords to D, in D there are several unused keywords, like "typedef", "macro", "body", "delete", "cent", "ucent"...
Comment #2 by issues.dlang — 2011-03-23T15:55:57Z
cent and ucent _should_ be kept around. They're _supposed_ to be unused keywords at this point. The idea is that if/when we need to add 128 bit integers to the language, we already have keywords for them. That way, we'll be able to add them without breaking code. macro should likely be kept in case we actually do something with AST macros (or some other macro-like mechanism) in a future version of the language. We may or may not care about keeping typedef once the construct that it's currently used has been removed. We could probably remove it. The same goes for delete. body... Well, I tend to agree that one is totally unnecessary. It probably simplifies the parsing a bit, but unless it's needed to keep the grammar context-free (which it might be, depending on what the exact grammar is for in, out, and body blocks - though I doubt it), it should be able to be removed. However, since it's in the language and its use hasn't changed at all over time (as far as I know), Waler at least thought that we should have it, and unless something about the situation or his opinion has changed in the interim, I doubt that he'll want to get rid of it.
Comment #3 by bugzilla — 2012-01-20T19:00:36Z
{ ... } { ... } just looks wrong. Hence the body keyword.