Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DIP1003: Remove body as a Keyword #48

Merged
merged 15 commits into from
Nov 19, 2016
Merged

Conversation

MetaLang
Copy link
Member

@MetaLang MetaLang commented Oct 11, 2016

This is the initial draft of DIP1003 for criticism and verification of acceptance criteria.

@mihails-strasuns
Copy link
Contributor

Thank you! I will provide initial feedback by the end of this week,

@JackStouffer
Copy link
Member

As I understand the DIP process, now is not the time to comment on the technical merits/demerits of the proposal. If that's not the case then let me know.

What we have right now is a DIP which recommends a breaking change, but then offers up several possible solutions to mitigate it and does not recommend one over the other. This feels wrong to me. I understand the situation we are in where Walter and Andrei may not agree with your deprecation process but they agree with the de-symbolizing of body. The root of the issue is that DIPs are supposed to be a policy recommendation in and of themselves; something that can be stamped "approved" or "rejected". Right now, this reads like a recommendation and not a plan.

I curious to hear Dicebot's opinion.

@MetaLang
Copy link
Member Author

MetaLang commented Oct 12, 2016

I have recommended a solution. See the Breaking Changes section:

Overall, it is the author's opinion that option 4 is the ideal path forward for implementing this proposal and minimizing breakage. However, this may not be feasible as it requires the implementation of conditional keywords... Therefore, the next best options are option 5 and option 6, which are "middle of the road" approaches.

I'll make it more clear that I recommend option 5 or 6.

@mihails-strasuns
Copy link
Contributor

@JackStouffer

As I understand the DIP process, now is not the time to comment on the technical merits/demerits of the proposal. If that's not the case then let me know.

It is not discouraged per se - simply not the main focus at current stage. But overall it is better to comment on it later after NG announcement, it will get more attention / dicussion that way.

Copy link
Contributor

@mihails-strasuns mihails-strasuns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented with some suggestions on both readability and content. Overall what I think it currently lacks most is focus in a way that it presents many approaches without putting too much effort into selling either of them. It risks becoming victim of the paradox of choice that way.

Considering all breaking change policies we are trying to enforce, only two essential approaches pass the checklist from my PoV:

  • conditional keyword
  • removing body altogether with very long (2+ years) deprecation period before it becomes available

If you agree with that, it may be better to focus on investigating just those two.

- [Usage of the Body Keyword](http://dlang.org/spec/function.html#BodyStatement)
- [Usage of the Function Keyword](https://dlang.org/spec/expression.html#FunctionLiteral)
- [Previous Discussion from 2011](http://forum.dlang.org/thread/imdro4$286k$1@digitalmars.com)
- [Current Forum Discussion on the usage of body in user code](http://forum.dlang.org/thread/nyrosepldsxabewksehb@forum.dlang.org)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As document will stay visible online for a while, it is better to separate all forum discussions in one sub-group and mark them with year instead of using words like "current"

- [Example of the word body used in an external C library ported to D](http://forum.dlang.org/post/lxdsvhygsaesjmkmavqp@forum.dlang.org)
- [Example 1 of the word body used in an external C++ library ported to D](https://github.com/d-gamedev-team/dchip/blob/55f43e5f0cf67c8bc190711b69eb16230fa6188e/src/dchip/cpBody.d#L184)
- [Example 2 of the word body used in an external C++ library ported to D](https://github.com/d-gamedev-team/dbox/blob/6f81fe065abec1e7def44fc777c5d8e9da936104/examples/demo/tests/bodytypes.d#L103)
- [Example 3 of the word body used in an external C++ library ported to D](https://github.com/rcorre/chipmunkd/commit/d6bde5b649c70a53f4295f522e660fae3c1e740f)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to move links with problematic examples to "rationale" section.

The proposed changes to D are very simple, and are as follows:

1. Remove `body` as a keyword
2. Allow the usage of the word "body" as a symbol name.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those 2 points are not enough to sufficiently described required change in semantics. You need to refer to cases proposed in "breaking changes" section which answer what happens with old contract syntax to complete it.

5. Add `function` as an optional keyword in the place of `body` and schedule the `body` keyword for deprecation. After this period allow `body` as a symbol name | Yes | Yes | Yes | Moderate | Moderate |
6. Allow the function body to optionally be annotated with `body`, but do not require it. Schedule the `body` keyword for deprecation. After this period, allow body as a symbol name | Yes | Yes | Yes | Moderate | Moderate | Makes function contracts 1 line shorter
7. Schedule `body` for deprecation and then removal. After this period, add `function` in its place and allow `body` as a symbol name | Yes | Yes | No | Difficult | Moderate |
8. Schedule `body` for deprecation and then removal. After this period, disallow its use to denote the function body and allow `body` as a symbol name | Yes | Yes | No | Difficult | Moderate | Makes function contracts 1 line shorter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all options that imply skipping deprecation process and breaking user code immediately. Such approaches have exactly 0% chance of being approved and thus only distract from essentials.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the same topic - instead of listing all combinations of possible approaches, it would be more practical to split required changes into independent blocks and list solutions for each of blocks. Something like this:

1) Existing usage of "body" in contracts:
    * deprecated, replacement suggested
    * remains valid
2) New suggested way of marking function body in contracts:
    * no keyword (just brackets)
    * "function"
    * conditional "body" keyword
3) How soon "body" can be used a symbol?
    * immediately (only applicable with conditional keyword case)
    * after "body" keyword deprecation term has passed

.. and after that pick few most practical combinations in your opinion with explanation why they are best.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only included those options for completeness' sake. Later on I specifiy that these are not recommended.

I'll look at splitting it up as you suggested.


### Rationale

Many D programmers complain about `body` being a keyword in D (see links section for relevant discussion). It is a commonly used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIR, you can use relative link to other section for ease of reading, something like this: [links](#Links)

### Breaking changes / deprecation process

Depending on how these changes are implemented, there will be little to no breakage,
and any breakage that _does_ occur will be done through the established deprecation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fail to see how this conclusion comes from previous statements. The way I read it, "minimal to no breakage" is only applicable to conditional keyword approach. All other approaches will cause a huge breakage and would need to undergo deprecation stage of several years at least before taking full power.


Depending on how these changes are implemented, there will be little to no breakage,
and any breakage that _does_ occur will be done through the established deprecation
process for breaking changes (first a warning, then deprecation, then removal).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current process is "deprecation -> (optionally) warning -> removal". Do you remember where you have noticed the process documented as you describe? We should have cleaned all cases by now but few could be left.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I don't.

process for breaking changes (first a warning, then deprecation, then removal).

It is the author's opinion that option 4 is the ideal path forward for implementing this proposal and minimizing breakage. However, this
may not be feasible as it requires the implementation of conditional keywords and the effort to implement them is currently unknown. Likewise,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like some research regarding feasibility of conditional keywords is necessary to be included into the DIP (at least in a form of links to existing NG discussions). That will certainly affect evaluation of proposal a lot.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't bother because Walter is against conditional keywords, so they will never be implemented. Actually it might be better to just remove this suggestion as it won't happen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it has a much better chance if used as a tool for better deprecation process and not come into language as full blow precedent. That is solution I'd prefer myself to be honest (use conditional keyword to start using "body" as a symbol early, but also deprecate its usage in contracts to be completely dropped out of keywords later).

Linking Walter comments on topic of conditional keywords would be useful too.

Copy link
Member Author

@MetaLang MetaLang Oct 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO conditional keywords need a whole other DIP to address them. I'd prefer to keep this DIP focused on the issue of removing body.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it is useful/necessary. Pretty much the only practical alternative is to deprecate current body keyword and wait 2+ years before it can be reclaimed. Surely, extra effort to try pushing for "fast and smooth" approach is worth saving everyone interested that 2 years.

If you don't want to do so, at the very least you need to make clear remark of why this path is not considered, with links to Walter stance on topic. "effort to implement them is currently unknown" is simply not a good wording for a DIP.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's true. Only compiler hackers know roughly how much effort would have to go into implementing conditional keywords. I'll see if I can find some stuff Walter's said.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only compiler hackers know roughly how much effort would have to go into implementing conditional keywords.

It shouldn't be mentioned in DIP at all in that case - implementation complexity for compiler internals should not effect approving the proposal. On the other hand, if there is a semantical complexity that is not related compiler internals, it has to be explained.


### Examples

How "body" might be used as a variable name in DOM-based code:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one good argument in favor of this DIP could come from examples of confusing compiler messages when one naively attempts to use "body" as a variable/argument name. As contract programming is not widely used in D, I have seen newbies being terribly confused by such occurrence.

It can be added to rationale too.

}
```

Examples of how code will change with this proposal:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should link these examples from relevant entries in description section.

@mihails-strasuns
Copy link
Contributor

@JackStouffer

The root of the issue is that DIPs are supposed to be a policy recommendation in and of themselves; something that can be stamped "approved" or "rejected". Right now, this reads like a recommendation and not a plan.

It is ok for DIP to propose few alternative (but related!) solutions for same problem as long as all of them are presented in good enough details and document structure allows to easily comprehend which parts are orthogonal. In that case A&W can simply pick one during approval.

However I agree that it is not good for options to be so many that picking one becomes a creative act of its own. Also see my paradox of choice remark in review comments.

@MetaLang
Copy link
Member Author

Well, in fairness I recommend one of two options and reject the others for various reasons. I'll look at pruning some of them, though.

@skl131313
Copy link

If it helps as an example I was able to get druntime, phobos, and dmd v2.071.2 compiling and running by removing "body" as a keyword and having "function" used as its' replacement. Only needed to use a relatively simple regex, took about an hour or two to make all the changes and double check. Only thing is I didn't go over changes in documentation for DMD, though for DMD's case, it'll probably have more that needs to be changed than any other codebase's documentation.

skl131313/phobos@bd7a84b
skl131313/druntime@8e7e80c
skl131313/dmd@5556d45

@MetaLang
Copy link
Member Author

I have made some of the requested changes. Still to do is add links to statements from Walter saying that he opposes conditional keywords, as well as adding a section on error messages when trying to use body as a symbol name.

@mihails-strasuns
Copy link
Contributor

Still to do is add links to statements from Walter saying that he opposes conditional keywords, as well as adding a section on error messages when trying to use body as a symbol name.

Ping. Any updates here?

@MetaLang
Copy link
Member Author

MetaLang commented Nov 4, 2016

None yet. I have some time this weekend so I will get to this then.

@MetaLang
Copy link
Member Author

MetaLang commented Nov 7, 2016

Well, I have been unable to find anything substantive other than this recent post by Walter. I have created a thread on the D mailing list asking him to make an official statement.

@MetaLang
Copy link
Member Author

MetaLang commented Nov 7, 2016

Still todo: a section on error messages when trying to use body as a symbol name.

@mihails-strasuns
Copy link
Contributor

Sounds reasonable. I'll wait if Walter provides more input on topic and make one final review pass - overall this DIP looks to be in quite decent shape.

to DMD on the basis that they will complicate the parser.

The grammar will not have to change if this option is implemented.

#### Option 2: Allow `function`, replace `body` after deprecation
Add `function` as an optional keyword in the place of `body` and schedule the `body` keyword for deprecation. After this
period allow `body` as a symbol name. This option will require some user effort to adjust their code and does not have
a migration path that is as easy as [Option 1](#option-1-conditional-keyword). However, it also does not require that conditional keywords be implented.
a migration path that is as easy as [Option 1](#option-1-contextual-keyword). However, it also does not require that contextual keywords be implented.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"implented" typo

@MetaLang
Copy link
Member Author

MetaLang commented Nov 7, 2016

Thinking more about this, I don't think it's worth it to include arguments relating to confusing error messages when trying to use the word body as a symbol. I don't think it has much, if anything to do with body, but instead with all keywords, and it's really just a quality of implementation issue that the error messages are confusing. Furthermore, when you start learning a new language, one of the first things you generally do is learn any new keywords that might not be in other languages that you know.

It just all around seems like a very weak argument, so I don't think it's worth including.

@jcd
Copy link

jcd commented Nov 8, 2016

I don't think this DIP can justify the breaking change it suggests. It doesn't bring any significant value but does break a bunch of existing code. And you can just prefix, suffix or change case of your name to e.g. body_ like you have to with all other keyword which isn't a big deal.

@mihails-strasuns
Copy link
Contributor

@MetaLang oops, I though I have already commented here but looks like it was only my imagination :X FYI: I am waiting for Andrei to publish his response on existing merged DIPs to use it as a sanity check before merging. Don't have any specific requirement on my side right now.

@MetaLang
Copy link
Member Author

MetaLang commented Nov 15, 2016

Ok, thanks. What's the timeframe for him responding to the merged DIPs?

@wilzbach
Copy link
Member

The deadline for the merged DIPs was two weeks ago - so I hope it will be
soon :)

On Tue, Nov 15, 2016, 13:42 MetaLang notifications@github.com wrote:

Ok, thanks. When is the timeframe for him responding to the merged DIPs?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#48 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AEKwdjs5hseodMik9gGiKNXexeJ2-Kvyks5q-ai8gaJpZM4KUIcU
.

@mihails-strasuns
Copy link
Contributor

Initial deadline was this Monday and it is obviously missed. I have just asked Andrei for an update.

@mihails-strasuns
Copy link
Contributor

@mihails-strasuns mihails-strasuns changed the title DIP1003 DIP1003: Remove body as a Keyword Nov 19, 2016
@mihails-strasuns mihails-strasuns merged commit ac5be9b into dlang:master Nov 19, 2016
@mihails-strasuns
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants