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

Added Frequently Asked Questions Page #202

Closed
wants to merge 42 commits into
base: master
from

Conversation

Projects
None yet
@AndrewBrinker
Contributor

AndrewBrinker commented Oct 22, 2015

This commit is the first draft of a new Frequently Asked Questions (FAQ) page for the Rust website. It provides answers for all but 4 of the 130 questions asked by the community, which can be found on the tracking issue #181.

The answers could use some review, as could the design and organization. I've tried to provide clear, concise answers that more often than not point people to the relevant portion of the Rust book.

Thoughts? Changes?

@rust-highfive

This comment has been minimized.

Show comment
Hide comment
@rust-highfive

rust-highfive Oct 22, 2015

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

rust-highfive commented Oct 22, 2015

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@brson

This comment has been minimized.

Show comment
Hide comment
@brson

brson Oct 23, 2015

Contributor

\o/ Woah! So much web site. Thanks.

Contributor

brson commented Oct 23, 2015

\o/ Woah! So much web site. Thanks.

@Diggsey

This comment has been minimized.

Show comment
Hide comment
@Diggsey

Diggsey Oct 23, 2015

Some thoughts while reading through it:

  • Why does "very small and limited runtime" link to lazy_static?
  • "Can I use globals across threads without unsafe" - You can use them as long as they're Sync and don't implement Drop, you just can't mutate them.
  • "there is no total ordering for floating point numbers" - Technically, the spec does define several possible total orderings for floating point numbers, at least one of which is implemented by an external crate - maybe link to it?
  • "How do I return a borrow to something I created from a function?" - Maybe suggest returning an owning type like String instead, and possibly mention Cow.
  • "How can I define a struct that contains a pointer to one of its own fields?" - I think you can actually do this, but it's useless as the struct becomes permanently borrowed (by itself), and so cannot ever be moved.
  • "What is the difference between consuming and moving/taking ownership?" - They're actually the same thing. When you call a method which consumes self, there's no requirement that self is dropped, it's simply moved into the method.
  • "Using Deref coercions! Strings and Vecs will automatically coerce to their respective slices when referenced" - The term "referenced" is very ambiguous here, maybe make it clear that you mean using &var.
  • "How do I do O(1) character access in a String?" - You can: str implements both Index and IndexMut, and so indexing is available via both String and &str. The caveats you mentioned still apply, but rather than getting out nonsense data, indexing will panic if it's not a valid UTF8 boundary.
  • "The char type is UCS4" - Actually, it's UTF32, which is subtly different because it disallows values outside the range 0-0x10FFFF, or within the range reserved for UTF16 surrogates. This is necessary to ensure that it can only contain valid unicode characters.
  • "Modules and Crates" - Maybe mention that use declarations are always relative to the crate root, rather than the current module, which is different from how name resolution works for everything else. This is one of the most confusing things when first using rust's module system.
  • "What is "monomorphisation" - C++ programmers will know this as template instantiation. In rust however, it's an implementation detail rather than a language feature.
  • "How does Rust's ownership system related to move semantics in C++?" - Maybe note that unlike in rust, in C++ destructors are still called after a value has been moved, ie. it's a destructive copy rather than an actual move.
  • "Does Rust have C++-style constructors?" - Mention that methods which construct value are typically named "new".

Diggsey commented Oct 23, 2015

Some thoughts while reading through it:

  • Why does "very small and limited runtime" link to lazy_static?
  • "Can I use globals across threads without unsafe" - You can use them as long as they're Sync and don't implement Drop, you just can't mutate them.
  • "there is no total ordering for floating point numbers" - Technically, the spec does define several possible total orderings for floating point numbers, at least one of which is implemented by an external crate - maybe link to it?
  • "How do I return a borrow to something I created from a function?" - Maybe suggest returning an owning type like String instead, and possibly mention Cow.
  • "How can I define a struct that contains a pointer to one of its own fields?" - I think you can actually do this, but it's useless as the struct becomes permanently borrowed (by itself), and so cannot ever be moved.
  • "What is the difference between consuming and moving/taking ownership?" - They're actually the same thing. When you call a method which consumes self, there's no requirement that self is dropped, it's simply moved into the method.
  • "Using Deref coercions! Strings and Vecs will automatically coerce to their respective slices when referenced" - The term "referenced" is very ambiguous here, maybe make it clear that you mean using &var.
  • "How do I do O(1) character access in a String?" - You can: str implements both Index and IndexMut, and so indexing is available via both String and &str. The caveats you mentioned still apply, but rather than getting out nonsense data, indexing will panic if it's not a valid UTF8 boundary.
  • "The char type is UCS4" - Actually, it's UTF32, which is subtly different because it disallows values outside the range 0-0x10FFFF, or within the range reserved for UTF16 surrogates. This is necessary to ensure that it can only contain valid unicode characters.
  • "Modules and Crates" - Maybe mention that use declarations are always relative to the crate root, rather than the current module, which is different from how name resolution works for everything else. This is one of the most confusing things when first using rust's module system.
  • "What is "monomorphisation" - C++ programmers will know this as template instantiation. In rust however, it's an implementation detail rather than a language feature.
  • "How does Rust's ownership system related to move semantics in C++?" - Maybe note that unlike in rust, in C++ destructors are still called after a value has been moved, ie. it's a destructive copy rather than an actual move.
  • "Does Rust have C++-style constructors?" - Mention that methods which construct value are typically named "new".
@AndrewBrinker

This comment has been minimized.

Show comment
Hide comment
@AndrewBrinker

AndrewBrinker Oct 23, 2015

Contributor

Wonderful! This is exactly the input I'm looking for:

Why does "very small and limited runtime" link to lazy_static?

Ah, mistake during editing. Fixing now.

"Can I use globals across threads without unsafe" - You can use them as long as they're Sync and don't implement Drop, you just can't mutate them.

Good to know. I've updated my answer accordingly.

"there is no total ordering for floating point numbers" - Technically, the spec does define several possible total orderings for floating point numbers, at least one of which is implemented by an external crate - maybe link to it?

Do you know which crate?

"How do I return a borrow to something I created from a function?" - Maybe suggest returning an owning type like String instead, and possibly mention Cow.

Good point. Updated.

"How can I define a struct that contains a pointer to one of its own fields?" - I think you can actually do this, but it's useless as the struct becomes permanently borrowed (by itself), and so cannot ever be moved.

Do you have some example code that does this? I'd like to provide an example if I can.

"What is the difference between consuming and moving/taking ownership?" - They're actually the same thing. When you call a method which consumes self, there's no requirement that self is dropped, it's simply moved into the method.

You're right. Fixed.

"Using Deref coercions! Strings and Vecs will automatically coerce to their respective slices when referenced" - The term "referenced" is very ambiguous here, maybe make it clear that you mean using &var.

I agree. I've clarified the language.

"How do I do O(1) character access in a String?" - You can: str implements both Index and IndexMut, and so indexing is available via both String and &str. The caveats you mentioned still apply, but rather than getting out nonsense data, indexing will panic if it's not a valid UTF8 boundary.

Good point. I've updated the answer.

"The char type is UCS4" - Actually, it's UTF32, which is subtly different because it disallows values outside the range 0-0x10FFFF, or within the range reserved for UTF16 surrogates. This is necessary to ensure that it can only contain valid unicode characters.

Yup. I copied this answer verbatim from a much older FAQ on the Rust website. It may have been true at one point (I don't know), but you're right that it isn't now.

"Modules and Crates" - Maybe mention that use declarations are always relative to the crate root, rather than the current module, which is different from how name resolution works for everything else. This is one of the most confusing things when first using rust's module system.

I've added an answer addressing this.

"What is "monomorphisation" - C++ programmers will know this as template instantiation. In rust however, it's an implementation detail rather than a language feature.

Good idea. Added.

"How does Rust's ownership system related to move semantics in C++?" - Maybe note that unlike in rust, in C++ destructors are still called after a value has been moved, ie. it's a destructive copy rather than an actual move.

Yup. Added.

"Does Rust have C++-style constructors?" - Mention that methods which construct value are typically named "new".

Added, along with a small example of such a function.

Contributor

AndrewBrinker commented Oct 23, 2015

Wonderful! This is exactly the input I'm looking for:

Why does "very small and limited runtime" link to lazy_static?

Ah, mistake during editing. Fixing now.

"Can I use globals across threads without unsafe" - You can use them as long as they're Sync and don't implement Drop, you just can't mutate them.

Good to know. I've updated my answer accordingly.

"there is no total ordering for floating point numbers" - Technically, the spec does define several possible total orderings for floating point numbers, at least one of which is implemented by an external crate - maybe link to it?

Do you know which crate?

"How do I return a borrow to something I created from a function?" - Maybe suggest returning an owning type like String instead, and possibly mention Cow.

Good point. Updated.

"How can I define a struct that contains a pointer to one of its own fields?" - I think you can actually do this, but it's useless as the struct becomes permanently borrowed (by itself), and so cannot ever be moved.

Do you have some example code that does this? I'd like to provide an example if I can.

"What is the difference between consuming and moving/taking ownership?" - They're actually the same thing. When you call a method which consumes self, there's no requirement that self is dropped, it's simply moved into the method.

You're right. Fixed.

"Using Deref coercions! Strings and Vecs will automatically coerce to their respective slices when referenced" - The term "referenced" is very ambiguous here, maybe make it clear that you mean using &var.

I agree. I've clarified the language.

"How do I do O(1) character access in a String?" - You can: str implements both Index and IndexMut, and so indexing is available via both String and &str. The caveats you mentioned still apply, but rather than getting out nonsense data, indexing will panic if it's not a valid UTF8 boundary.

Good point. I've updated the answer.

"The char type is UCS4" - Actually, it's UTF32, which is subtly different because it disallows values outside the range 0-0x10FFFF, or within the range reserved for UTF16 surrogates. This is necessary to ensure that it can only contain valid unicode characters.

Yup. I copied this answer verbatim from a much older FAQ on the Rust website. It may have been true at one point (I don't know), but you're right that it isn't now.

"Modules and Crates" - Maybe mention that use declarations are always relative to the crate root, rather than the current module, which is different from how name resolution works for everything else. This is one of the most confusing things when first using rust's module system.

I've added an answer addressing this.

"What is "monomorphisation" - C++ programmers will know this as template instantiation. In rust however, it's an implementation detail rather than a language feature.

Good idea. Added.

"How does Rust's ownership system related to move semantics in C++?" - Maybe note that unlike in rust, in C++ destructors are still called after a value has been moved, ie. it's a destructive copy rather than an actual move.

Yup. Added.

"Does Rust have C++-style constructors?" - Mention that methods which construct value are typically named "new".

Added, along with a small example of such a function.

@AndrewBrinker

This comment has been minimized.

Show comment
Hide comment
@AndrewBrinker

AndrewBrinker Oct 23, 2015

Contributor

Before anything gets merged I do want to note that four questions remain unanswered and commented out in the source code. This does not necessarily need to block merging, but if someone can answer any of these questions before we merge that would be much appreciated. If not, then afterward works.

Contributor

AndrewBrinker commented Oct 23, 2015

Before anything gets merged I do want to note that four questions remain unanswered and commented out in the source code. This does not necessarily need to block merging, but if someone can answer any of these questions before we merge that would be much appreciated. If not, then afterward works.

@Diggsey

This comment has been minimized.

Show comment
Hide comment
@Diggsey

Diggsey Oct 23, 2015

Do you know which crate?

https://crates.io/crates/ordered-float

Do you have some example code that does this? I'd like to provide an example if I can.

http://is.gd/MDSXVA

Diggsey commented Oct 23, 2015

Do you know which crate?

https://crates.io/crates/ordered-float

Do you have some example code that does this? I'd like to provide an example if I can.

http://is.gd/MDSXVA

@AndrewBrinker

This comment has been minimized.

Show comment
Hide comment
@AndrewBrinker

AndrewBrinker Oct 24, 2015

Contributor

Okay, I've updated it with that information.

Contributor

AndrewBrinker commented Oct 24, 2015

Okay, I've updated it with that information.

@AndrewBrinker

This comment has been minimized.

Show comment
Hide comment
@AndrewBrinker

AndrewBrinker Nov 4, 2015

Contributor

I think this is ready to merge, unless there are concerns about the specialized styling for the page.

Contributor

AndrewBrinker commented Nov 4, 2015

I think this is ready to merge, unless there are concerns about the specialized styling for the page.

@brson

This comment has been minimized.

Show comment
Hide comment
Contributor

brson commented Nov 5, 2015

@steveklabnik

This comment has been minimized.

Show comment
Hide comment
@steveklabnik
Member

steveklabnik commented Nov 5, 2015

😍

Show outdated Hide outdated faq.md
Show outdated Hide outdated _layouts/faq.html
@aturon

This comment has been minimized.

Show comment
Hide comment
@aturon

aturon Nov 5, 2015

Member

cc me. We need to advertise this PR very widely, get the whole community's eyes on it.

Member

aturon commented Nov 5, 2015

cc me. We need to advertise this PR very widely, get the whole community's eyes on it.

@edunham

This comment has been minimized.

Show comment
Hide comment
@edunham

edunham Nov 5, 2015

Member

Could this be formatted so each question has an anchor, and I can link to a specific section? I imagine needing to link particular questions to new users quite frequently, and it'd be better to include the section in the URL than to tell them "click here and scrolll"

Member

edunham commented Nov 5, 2015

Could this be formatted so each question has an anchor, and I can link to a specific section? I imagine needing to link particular questions to new users quite frequently, and it'd be better to include the section in the URL than to tell them "click here and scrolll"

Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
@steveklabnik

This comment has been minimized.

Show comment
Hide comment
@steveklabnik

steveklabnik Jan 7, 2016

Member

@AndrewBrinker thank you so much for putting the work into this. It's awesome. 👍

Member

steveklabnik commented Jan 7, 2016

@AndrewBrinker thank you so much for putting the work into this. It's awesome. 👍

Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
@AndrewBrinker

This comment has been minimized.

Show comment
Hide comment
@AndrewBrinker

AndrewBrinker Jan 7, 2016

Contributor

Obviously things aren't quite done yet. I have some more direct feedback to go over, and I need to address @brson's previous points. But I just want to say that this has been a really great process, and I can't wait to get this thing polished and merged. Thanks for all the help and feedback, everyone.

Oh, and no problem @steveklabnik. It's been my pleasure.

Contributor

AndrewBrinker commented Jan 7, 2016

Obviously things aren't quite done yet. I have some more direct feedback to go over, and I need to address @brson's previous points. But I just want to say that this has been a really great process, and I can't wait to get this thing polished and merged. Thanks for all the help and feedback, everyone.

Oh, and no problem @steveklabnik. It's been my pleasure.

Show outdated Hide outdated faq.md
@pnkfelix

This comment has been minimized.

Show comment
Hide comment
@pnkfelix

pnkfelix Jan 8, 2016

Member

(great job incorporating feedback @AndrewBrinker ; I was especially impressed by the places where I said "oh man this is wrong but I don't know how to fix it" (and I threw up my hands) and you subsequently found a solution, quite quickly!)

Member

pnkfelix commented Jan 8, 2016

(great job incorporating feedback @AndrewBrinker ; I was especially impressed by the places where I said "oh man this is wrong but I don't know how to fix it" (and I threw up my hands) and you subsequently found a solution, quite quickly!)

@AndrewBrinker

This comment has been minimized.

Show comment
Hide comment
@AndrewBrinker

AndrewBrinker Jan 8, 2016

Contributor

Thanks @pnkfelix! I'm glad you like what I've done. It wouldn't have been possible without all the great feedback from everyone. The current version is much much better than my first draft. It'll be interesting to see how the document evolves over time, and to see what sort of feedback we get once it's up on the site.

@brson, I know you have some style changes you'd like made, and that your plan is to wrap this up yourself (I'm guessing squash down all the commits in this PR). Should I incorporate the style changes here, or is that something you'd like to do?

Also, I am still working on your big list of thoughts. The deref coercion and higher-kinded types answers have been updated, but the rest still need to be addressed properly.

Contributor

AndrewBrinker commented Jan 8, 2016

Thanks @pnkfelix! I'm glad you like what I've done. It wouldn't have been possible without all the great feedback from everyone. The current version is much much better than my first draft. It'll be interesting to see how the document evolves over time, and to see what sort of feedback we get once it's up on the site.

@brson, I know you have some style changes you'd like made, and that your plan is to wrap this up yourself (I'm guessing squash down all the commits in this PR). Should I incorporate the style changes here, or is that something you'd like to do?

Also, I am still working on your big list of thoughts. The deref coercion and higher-kinded types answers have been updated, but the rest still need to be addressed properly.

@AndrewBrinker

This comment has been minimized.

Show comment
Hide comment
@AndrewBrinker

AndrewBrinker Jan 8, 2016

Contributor

Also, I started adding a bunch of missing links to the API docs at @steveklabnik's suggestion, but I'm not finished yet.

Contributor

AndrewBrinker commented Jan 8, 2016

Also, I started adding a bunch of missing links to the API docs at @steveklabnik's suggestion, but I'm not finished yet.

Show outdated Hide outdated faq.md
@tshepang

This comment has been minimized.

Show comment
Hide comment
@tshepang

tshepang Jan 8, 2016

Contributor
Contributor

tshepang commented Jan 8, 2016

Show outdated Hide outdated faq.md
Show outdated Hide outdated faq.md
### Does Rust allow non-constant-expression values for globals?
No. Globals cannot have a non-constant-expression constructor and cannot have a destructor at all. Static constructors are undesirable because portably ensuring a static initialization order is difficult. Life before main is often considered a misfeature, so Rust does not allow it.

This comment has been minimized.

@solson

solson Jan 8, 2016

Member

This answer should mention the lazy_static crate as a workaround.

@solson

solson Jan 8, 2016

Member

This answer should mention the lazy_static crate as a workaround.

@solson

This comment has been minimized.

Show comment
Hide comment
@solson

solson Jan 8, 2016

Member

This is shaping up to be quite excellent! Thanks to everyone who's been working so hard on this. 😄

Member

solson commented Jan 8, 2016

This is shaping up to be quite excellent! Thanks to everyone who's been working so hard on this. 😄

@AndrewBrinker

This comment has been minimized.

Show comment
Hide comment
@AndrewBrinker

AndrewBrinker Jan 9, 2016

Contributor

Okay, I've now made changes addressing all but the following points of @brson's:

  • The exceptions answer still needs a rewrite
  • We still don't have an answer on Rust's name (I'm actually not sure what the real explanation is here)
  • The "Concurrency," "Macros," and "Debugging" sections are still small (I think this is fine for now. They will almost certainly grow in future revisions based on community feedback).

I am also still going through the entire document adding links to the API docs.

Contributor

AndrewBrinker commented Jan 9, 2016

Okay, I've now made changes addressing all but the following points of @brson's:

  • The exceptions answer still needs a rewrite
  • We still don't have an answer on Rust's name (I'm actually not sure what the real explanation is here)
  • The "Concurrency," "Macros," and "Debugging" sections are still small (I think this is fine for now. They will almost certainly grow in future revisions based on community feedback).

I am also still going through the entire document adding links to the API docs.

@solson

This comment has been minimized.

Show comment
Hide comment
@solson

solson Jan 9, 2016

This and the above should use x % 2 != 0 since e.g. -3i64 % 2 == -1.

solson commented on faq.md in ea304ed Jan 9, 2016

This and the above should use x % 2 != 0 since e.g. -3i64 % 2 == -1.

@AndrewBrinker

This comment has been minimized.

Show comment
Hide comment
@AndrewBrinker

AndrewBrinker Jan 9, 2016

Contributor

Okay, I've finished adding the links to the API docs, and I've made the correction suggested by @tsion.

Contributor

AndrewBrinker commented Jan 9, 2016

Okay, I've finished adding the links to the API docs, and I've made the correction suggested by @tsion.

@brson

This comment has been minimized.

Show comment
Hide comment
@brson

brson Jan 12, 2016

Contributor

@brson, I know you have some style changes you'd like made, and that your plan is to wrap this up yourself (I'm guessing squash down all the commits in this PR). Should I incorporate the style changes here, or is that something you'd like to do?

I'll take care of merging the styles. I am going to open one PR that contains all pending website changes.

Contributor

brson commented Jan 12, 2016

@brson, I know you have some style changes you'd like made, and that your plan is to wrap this up yourself (I'm guessing squash down all the commits in this PR). Should I incorporate the style changes here, or is that something you'd like to do?

I'll take care of merging the styles. I am going to open one PR that contains all pending website changes.

@brson

This comment has been minimized.

Show comment
Hide comment
@brson

brson Jan 12, 2016

Contributor

My previous points have been addressed to my satisfaction (for the most part, see below), and I'm intending to merge this with the other open PRs and my style changes into one fresh PR for landing.

The only remaining big concerns I have about the FAQ are: HKT section, while better, in the first section makes it sound like Rust has HKT by saying that type constructors that exist are KHTs; there's still no Q&A for 'What does "Rust" mean'.

I'm happy to address those in follow ups though.

Contributor

brson commented Jan 12, 2016

My previous points have been addressed to my satisfaction (for the most part, see below), and I'm intending to merge this with the other open PRs and my style changes into one fresh PR for landing.

The only remaining big concerns I have about the FAQ are: HKT section, while better, in the first section makes it sound like Rust has HKT by saying that type constructors that exist are KHTs; there's still no Q&A for 'What does "Rust" mean'.

I'm happy to address those in follow ups though.

@brson

This comment has been minimized.

Show comment
Hide comment
@brson

brson Jan 12, 2016

Contributor

Here's the combined PR.

Thank you everybody for the amazing reviews and @AndrewBrinker for putting it all together. We're almost done.

Contributor

brson commented Jan 12, 2016

Here's the combined PR.

Thank you everybody for the amazing reviews and @AndrewBrinker for putting it all together. We're almost done.

@brson brson closed this Jan 12, 2016

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