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

[READY FOR REVIEW] Ch15 edits #898

Merged
merged 18 commits into from
Sep 19, 2017
Merged

[READY FOR REVIEW] Ch15 edits #898

merged 18 commits into from
Sep 19, 2017

Conversation

carols10cents
Copy link
Member

@carols10cents carols10cents commented Aug 25, 2017

Ok I think this is ready for review now @steveklabnik <3

@carols10cents carols10cents force-pushed the ch15-edits branch 5 times, most recently from 79c08bf to 6b01ff8 Compare September 1, 2017 21:39
@carols10cents carols10cents changed the title [NOT DONE YET] Ch15 edits [READY FOR REVIEW] Ch15 edits Sep 11, 2017
#### A Use Case for Interior Mutability: Mock Objects

A *mock object* is the general programming concept for a type that stands in
the place of another type during testing. Mock objects simulate real objects,
Copy link
Member

Choose a reason for hiding this comment

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

A test double is the generic thing that stands in for another. A mock object is a specific type of double that records what happens.

Suggest rewording to

A test double is the general programming concept for a type that stands in the place of another type during testing. Mock objects are specific types of test doubles that record what happens during a test so that we can assert that the correct actions took place.

Copy link
Member

@steveklabnik steveklabnik left a comment

Choose a reason for hiding this comment

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

lookin great!

ordinary struct are that smart pointers implement the `Deref` and `Drop`
traits, and in this chapter we’ll be discussing both of those traits and why
they’re important to smart pointers.
A *pointer* is the generic programming concept for an address to a location
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 finding both the original sentence and this re-word a bit awkward; what about

A pointer is a general concept for a variable that contains an address in memory. This address refers to, or "points at", some other data.

*reference*, which we learned about in Chapter 4. References are indicated by
the `&` symbol and borrow the value that they point to. They don't have any
special abilities other than referring to data, but they also don't have any
more overhead than they need to do straightforward referencing, so they're used
Copy link
Member

Choose a reason for hiding this comment

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

they also don't have any overhead, so they're used


* `Box<T>` for allocating values on the heap
* `Rc<T>`, a reference counted type that enables multiple ownership
* `Ref` and `RefMut`, accessed through `RefCell<T>`, a type that enforces the
Copy link
Member

Choose a reason for hiding this comment

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

Ref<T> and RefMut<T>

advantage to this can be, help them know when they'd use this? -->
<!-- Correct! Recap below: /Carol -->

Boxes don't have a lot of performance overhead, but they don't have a lot of
Copy link
Member

Choose a reason for hiding this comment

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

I am slightly unsure about this phrasing; boxes have no overhead other than being on the heap. Not sure how to best communicate that....

Copy link
Member Author

Choose a reason for hiding this comment

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

There's the redirection, yeah? Isn't that a bit of overhead? I'm fine saying "Boxes don't have performance overhead other than being on the heap instead of on the stack", how does that sound?

Copy link
Member

Choose a reason for hiding this comment

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

That "redirection" is a consequence of being on the heap, nothing else 😄

how does that sound?

👍

### Using a `Box` to Store Data on the Heap

Before we get into a use case for `Box`, let's get familiar with the syntax and
how to interact with values stored within a `Box`.
Copy link
Member

Choose a reason for hiding this comment

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

either box or Box<T> in this paragraph

turn it on. Others can come into the room and watch the TV. When the last
person leaves the room, they turn the TV off because it's no longer being used.
If someone turns the TV off while others are still watching it, there'd be
uproar from the remaining TV watchers!
Copy link
Member

Choose a reason for hiding this comment

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

👍

function and pass a reference to the `Rc` in `a` as an argument.

We could have called `a.clone()` rather than `Rc::clone(&a)`, but Rust
convention is to use `Rc::clone` in this case. The implementation of `clone`
Copy link
Member

Choose a reason for hiding this comment

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

... it is?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

uuuuuuuuuuuuugh welp time to update my brain. thanks ❤️

certain memory safe scenarios are then allowed, whereas they are disallowed by
the compile time checks. Static analysis, like the Rust compiler, is inherently
conservative. Some properties of code are impossible to detect by analyzing the
code: the most famous exampled is the Halting Problem, which is out of scope of
Copy link
Member

Choose a reason for hiding this comment

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

example

RefCell<T> is, perhaps a succinct round up would help? -->
<!-- Done /Carol -->

To recap the reasons to choose `Box<T>`, `Rc<T>`, or `RefCell<T>`:
Copy link
Member

Choose a reason for hiding this comment

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

putting this at this part of the book feels weird to me; it feels like it should be a summary, but we don't really have "end of the chapter summaries" or anything. hm

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah i just put it in here to satisfy the comment. it feels a little weird in this spot too :-/ wdyt-- take it out entirely? we do have the ## Summary section at the end of 15-06?

Copy link
Member

Choose a reason for hiding this comment

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

yeah either take it out or put it in the summary. i'd lean towards taking it out

Copy link
Member Author

Choose a reason for hiding this comment

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

so natalie said she really liked this section here, that it tied things together before getting deep into interior mutability.

Copy link
Member

Choose a reason for hiding this comment

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

hmmmmmmmmmmm

`Mutex<T>`, which offers interior mutability that's safe to use across threads,
and we'll be discussing its use in the next chapter on concurrency. Check out
the standard library docs for more details on the differences between these
types.
Copy link
Member

Choose a reason for hiding this comment

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

this whole example is excellent, thanks so much for all the work on it ❤️

@carols10cents
Copy link
Member Author

@steveklabnik could you review these changes that i made to address comments from you, jake, natalie, and open issues for this chapter? 17da5ac...2fa362e

@steveklabnik
Copy link
Member

Looks good to me, though one of those commit messages is now incorrect in the other direction, as I commented on the issue it's addressing.

@carols10cents
Copy link
Member Author

ok, i fixed the commit message and i'm merging this and sending over to nostarch :) thank youuuuuuu

@carols10cents carols10cents merged commit 017f511 into master Sep 19, 2017
@carols10cents carols10cents deleted the ch15-edits branch September 19, 2017 17:58
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.

3 participants