-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tutorial: potential trip-up for beginners as a consequence of bug in for iteration #15409
Comments
Yeah, I'm not sure what the right solution is here. Maybe put a comment above the enum saying "this is built-in, you dont need to declare it?" |
@steveklabnik But when some people follow tutorials they like to follow along by testing the code for themselves, even if the code is just a reimplementation of something that could be imported or used directly anyway. Maybe they just want to practice the syntax by typing in the examples and seeing if it compiles, for example. |
Then maybe it should say "if you re-implement this, it will kinda work, but bad things will happen?" |
@steveklabnik That is a possibility, but it might not instil much confidence in the language. ^^ Though I guess that relatively early adopters have already mentally prepared themselves for rough edges, anyway. A third possibility is to keep the enum name, but change the name of the constructors: enum Option<T> { // or Maybe<T>...
Just(T),
Nothing
} This doesn't create an error. A fourth possibility is to mangle the name of the constructors, i.e. |
This was fixed in the language by #15809 |
minor: Sync from downstream
In section 17. Generics, some example code is given:
This might cause problems for readers who are typing in and trying out code that the tutorial provides (which is alluded to as a way of reading the tutorial in the current introduction). The reason is that creating an enum with some constructor that is the same as one of the constructors of the
Option
type from the std module will create some weird shadowing-behaviour (see this issue). This kind of error is non-obvious, at least to a beginner, and the error message arises in thefor
loop instead of the enum declaration, making things more confusing.Replacing the
Option
example with some other artificial (not found in std module) example would mitigate this risk, but on the other hand it would not give an excuse to introduce theOption
type and its role.The text was updated successfully, but these errors were encountered: