-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Not the best example in "6.3 Concise Control Flow with if let". #1401
Comments
It does, thanks! you're right that being able to use the binding is the key feature of |
My personal inclination is that |
In my humble opinion, we are talking about a book for a newbie here. And we have just told them that " The thing is, in case of |
I got |
I am a rust newbie too (Java coder). I love the book, and start to be very excited about the language, and while at times some things are explained maybe a bit to verbosely for me, I would not change that at all... I consider it very good, thank you!
So I give a +1 to @andy-rust and @imbolc here. |
You'd better think about Maybe it would be better to rename the whole operator, call it |
hmm... thanks @andy-rust ! |
@andywswan what would happen to cases where I want to do |
@L0uisc sure "else" should work as usual. But it doesn't matter, because everyone seems to be happy with "if let" as it is. |
I am reading the book for the first time and have only advanced to Chapter 10. When I first read about |
No amount of explanations would be enough for me because of the fact, that in the case of The only right way of proceeding would be to open an RFC with a proposal of replacing this vague |
I think the Just FYI: there is |
well, I think more often, than not there will be binding afterall, like The book earlier states that "let is used to introduce a binding" so we would have to change it to "let is MOSTLY used to introduce a binding, except for some use cases of if let", which begs the question: why bother to create an exception in the first place? Why do not use a more clear operator? Just google "rust if let", a lot of folks are greatly confused, some went as far as digging to MIR in attempt to get to the roots of this http://patshaughnessy.net/2018/1/18/learning-rust-if-let-vs--match |
could we not at least put a note into the book then, that this might be confusing? |
When I saw the example in section 6.3, my head exploded: "there is a r-value on the left side of '=' in an assignment???" After some time grumping, I tried to figure out what is happening, and learned about pattern matching. I still think that
|
I think it is better to hold off on the destructuring and such until chapter 19 as it is currently. I think there should simply be a paragraph explaining that, for now, |
Am I mistaken, or is it not possible to have also a binding in an
.. so the confusion is only with the matching pattern part of the language? with the proposed |
For me, the confusion was the pattern matching. Destructuring is secondary, as in my mind at least, it is a consequence of patterns and binding. The other confusing thing for me is that in the example, there is no binding because the pattern is a constant, and |
So, I have a possible solution to some of the confusion with this exact statement and it took me a bit to understand. It would have helped if the previous example with the match statement was shown exactly in the
paired with
That would help parse the new statement as "identical". It took me a long time to figure out that the |
Update books ## reference 1 commits in 4884fe45c14f8b22121760fb117181bb4da8dfe0..da6ea9b03f74cae0a292f40315723d7a3a973637 2021-07-28 21:31:28 -0700 to 2021-08-19 21:28:10 -0700 - Allow users to change status labels (rust-lang/reference#1083) ## book 7 commits in 7e49659102f0977d9142190e1ba23345c0f00eb1..687e21bde2ea10c261f79fa14797c5137425098d 2021-08-03 21:41:35 -0400 to 2021-08-18 20:48:38 -0400 - Small tweaks to Ferris size and position - Retain previous height: auto just in case - Shrink and move ferris when possible - Snapshot chapter 6 for nostarch - Demonstrate variable as catch-all for match. Fixes rust-lang/book#1868. - Improve the if let example to have a binding pattern. Fixes rust-lang/book#1401. - Fixes typo (rust-lang/book#2816) ## rust-by-example 1 commits in 0dc9cd4e89f00cb5230f120e1a083916386e422b..04f489c889235fe3b6dfe678ae5410d07deda958 2021-07-23 09:14:27 -0300 to 2021-08-17 08:01:20 -0300 - Grammar mistake (rust-lang/rust-by-example#1456) ## rustc-dev-guide 5 commits in c4644b427cbdaafc7a87be0ccdf5d8aaa07ac35f..cf0e151b7925a40f13fbc6573c6f97d5f94c7c17 2021-08-10 20:41:44 +0900 to 2021-08-22 11:47:02 -0300 - Fix typo “a Rc” → “an Rc” (rust-lang/rustc-dev-guide#1191) - Expand THIR section with more details (rust-lang/rustc-dev-guide#1183) - Remove docs for old -Z profile-queries flag - update mdbook version to latest - allow to quickly edit a page directly on github
Hey guys!
First of all - thank you very much for the great language and the great book. I'm new to coding, so I'm sorry if anything (or everything) I say is stupid.
At least for me, there is a very bad example in the "6.3 Concise Control Flow with if let" chapter. It says:
I had been somewhat at a loss as to why or how this expression is any better than say
and it took me some time to come to the conclusion that in this particular case it probably isn't better at all, if not worse for arguably "weird" (for me in that state of mind) syntax. By weird, I mean that at the time the part after "if" looked like
let 3 = x
for me, which had just turned my head around :)
Long story short, I think it is more clear to explain "if let" through use of unwrapping the optional value (if it is there), like so:
I hope that makes sense.
The text was updated successfully, but these errors were encountered: