Skip to content

Improve docs for std.typecons.scoped #3016

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

Closed
wants to merge 2 commits into from
Closed

Conversation

ntrel
Copy link
Contributor

@ntrel ntrel commented Feb 20, 2015

Show automatic destruction of scoped result.
Show how scoped can lead to invalid class references.
Show scoped member variable initialization.
Move alias example before Restrictions section, which uses alias.

@ntrel ntrel force-pushed the scoped-docs branch 2 times, most recently from b477325 to 446d330 Compare February 20, 2015 17:37
The class's destructor will be called when the result of `scoped()` is
itself destroyed.

Class instances can be embedded in a `class` or `struct` as member
Copy link
Contributor

Choose a reason for hiding this comment

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

This sentence feels like a random fact. I see two points here: (a) With scoped class instance can be placed like struct instances and (b) the type typeof(scoped!Class(args)) has to be used to use a scoped class as a member variable. The second point is actual information (I did not know that before). Maybe you can make this point more pronounced. In addition a one-sentence explanation would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

Please suggest any additional wording if needed.

@ntrel
Copy link
Contributor Author

ntrel commented Mar 13, 2015

ping

@@ -5141,7 +5141,16 @@ therefore avoiding the overhead of $(D new). This facility is unsafe;
it is the responsibility of the user to not escape a reference to the
object outside the scope.

Note: it's illegal to move a class reference even if you are sure there
The class's destructor will be called when the result of `scoped()` is
Copy link
Member

Choose a reason for hiding this comment

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

possessive for an 's' ending word is just a trailing apostrophe: class' destructor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks.

@schveiguy
Copy link
Member

Other than the nitpick, looks good.

scoped. See below for an example.

Note:
It's illegal to move a class reference even if you are sure there
Copy link
Member

Choose a reason for hiding this comment

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

What does it mean to "move a class reference"? Assign it to another class reference? Call std.algorithm.mutation.move on it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I didn't like this language either, but I didn't know how to improve it, so I left it as-is.

Copy link
Member

Choose a reason for hiding this comment

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

But I actually don't understand what it means. What does it mean "it's illegal to move a class reference"? What does "move" mean in this context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, I didn't write it.

Copy link
Member

Choose a reason for hiding this comment

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

Alright, let's leave this to a future PR. Better to have a partially-better doc than to have no improvements at all.

Copy link
Member

Choose a reason for hiding this comment

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

It's a poorly written comment. Should be "It's illegal to move an object's data". It's perfectly legal to move a pointer/reference.

Copy link
Member

Choose a reason for hiding this comment

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

I still don't quite understand exactly what that means, though. How do you "move an object's data" if said object is being held by Scoped? Copy it elsewhere and invalidate the scoped reference? Manually overwrite the scoped reference pointer? I'm not seeing the point of that comment. Obviously, I'm missing something obvious, but that just shows how badly written that comment is? :-P

ntrel added 2 commits March 24, 2015 12:57
Show automatic destruction of `scoped` result.
Show how `scoped` can lead to invalid class references.
Show scoped member variable initialization.
Move alias example before *Restrictions* section, which uses alias.
@ntrel
Copy link
Contributor Author

ntrel commented Mar 24, 2015

Added newlines, destroy(b1) and simple Params: section for scoped(args).
Fixed note about moving a class instance - see ffc9ae4.

@ntrel
Copy link
Contributor Author

ntrel commented Apr 17, 2015

ping

@DmitryOlshansky
Copy link
Member

LGTM

@DmitryOlshansky
Copy link
Member

Auto-merge toggled on

@DmitryOlshansky
Copy link
Member

Auto-merge toggled off

@DmitryOlshansky
Copy link
Member

Fails auto-tester somewhere deeper in std.typcons, memory corruption?

@quickfur
Copy link
Member

ping @ntrel

alias makeScopedA = scoped!A;
auto a3 = makeScopedA();
auto a4 = makeScopedA(1);

// Restrictions
static assert(!is(typeof({
Copy link
Member

Choose a reason for hiding this comment

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

This assert is failing for some reason. (Tested on git HEAD, I had to rebase on Phobos master to get it to compile, but make -f posix.mak unittest aborts with an assertion failure on this line.)

Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing something broke with scoped, and it now compiles with std.algorithm.move even though it should not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think move probably always did work with scoped. In my updated #4129, I changed the assert to version(Bug) instead.

@DmitryOlshansky
Copy link
Member

Any plans to revive this @ntrel ?

@ntrel
Copy link
Contributor Author

ntrel commented Aug 30, 2015

No plans really, I've not been doing any development for a while. Thanks for reviews though.

@DmitryOlshansky
Copy link
Member

I've not been doing any development for a while. Thanks for reviews though.

Then I'm going to close it, feel free to create a new pull.

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

Successfully merging this pull request may close these issues.

5 participants