Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up`use` isn't an import statement. #460
Comments
This comment has been minimized.
This comment has been minimized.
|
What would be a way of describing what As someone who isn't a PL researcher and is more of a tell-me-what-i-need-to-do-to-accomplish-my-goal sort of programmer, I don't have a precise definition of "import" in my mind, it's more like "using I don't want the book to be wrong, but I also don't want it to get hung up on terminology. |
carols10cents
assigned
steveklabnik
Feb 21, 2017
carols10cents
added
the
Q for ourselves
label
Feb 21, 2017
This comment has been minimized.
This comment has been minimized.
|
Merriam Webster defines import as: to bring from a foreign or external source. If you describe I'd suggest changing the first example to be:
Removing the Then in the next example, As for the 'hung up on terminology' part, the only reason I looked at this is because there's a threat proposing changing the language because people are confused. And I'd much rather get |
This comment has been minimized.
This comment has been minimized.
Yes,
This is non-idiomatic Rust though. I understand the desire to get rid of a concept, but I also really don't want to show off worse code because of it. In general, the Guessing Game is meant to be a fast and loose intro. You should get the gist of things, but it doesn't go into a lot of depth. It's also the most well-trodden piece of text we have; it's the same as in the original book, where it was the intro there, and is actually in and of itself older than the book, IIRC. We don't even expect people to have read the Guessing Game, it's skippable if desired. |
This comment has been minimized.
This comment has been minimized.
|
I think how a given person perceives the word "use" or "import" depends on their background. Coming from C# and JavaScript, I instantly associated "use" with "using", and didn't expect any literal importing. I think the usage of "import" in the Guessing Game is rather ambiguous and will likely mean different things to different people, potentially some of them incorrect, but that seems OK for an introductory program. |
This comment has been minimized.
This comment has been minimized.
|
At a high level, I'd much rather sit on the fence when it comes to the content of tutorials. However, given that people find the module system in Rust to be confusing and are suggesting changes to the language which I find to be an extreme solution, I'm trying to improve the docs as a first attempt at remedying the situation. If the lang team is spending valuable time considering changes (which I think are misguided) to the language to make it easier to understand, I don't get why this level of resistance is being given to an attempt at improving the docs, in the name of "well, it's just introductory text, how could being more precise with the wording make any difference?"
I suppose we could reinterpret the word import to mean anything either of us wanted. But if we look at functions, modules, types, scopes, etc as nodes in a graph with the start node being the current scope and the edges being names, then we have a mental model for how name lookup works. Follow edges based on their name until we reach the appropriate item from the current scope. This model allows us to consider 'foreign' things to be things we currently cannot reach, because there are no connections from the current scope that allows access to them. Importing would be the process of adding nodes to the graph along with edges, which would allow access. That is, it brings 'items' from a foreign source. However, Now, this definition is pedantic and I don't expect a new programmer or user of Rust to read a tutorial with the word import and immediately think about name lookup and graph theory. However, words are important and picking the right ones to describe the appropriate concepts is also important. If import is used to describe what
I personally use fully qualified names when initially writing code and only add In any case, I'm not suggesting it be removed anyways, I'm suggesting that
Being fast and loose is dangerous though, because people can walk away with false first impressions. If you think of each chapter in the book as a compass, then they should all point in the same direction but be of different length (i.e. different depth of knowledge). And it being the most well-trodden could just explain why people have issues with learning the difference between use and mod. I'm not attempting to point fingers, but rather, pointing out that something is popular doesn't mean that it's correct. And the fact that it's skippable is irrelevant when considering it's correctness when not skipped. |
This comment has been minimized.
This comment has been minimized.
|
I learned stuff while reading this, thanks @ahmedcharles. Also good points. We have to be careful with terminology. I support the idea of showing an example of code with and without |
ahmedcharles commentedFeb 21, 2017
There has been some recent discussion about the confusion people having with the difference between
use,modandextern crate. The guessing game tutorial contains:It uses the word import, to refer to what the
usestatement does. However, theusestatement doesn't actually 'import' things in the same sense that an#includein C++ would or arequirein JS would.extern crateis the only way to import code external to the current crate.modis also an import like statement, but Rust is unique in that it uses two keyword phrases to identify internal vs external imports. I suppose this is similar to the difference between#include "foo.h"and#include <foo.h>(which is that the version with " will search the current directory before other include paths).Anyways,
useintroduces a new binding (in programming language theory parlance), which is a new name for something else which already exists. The tutorial glosses over the fact thatuse std::io;is only possible because there is an implicitextern crate std;which is the actual import statement. However, it's probably a good thing that the tutorial not mention that specifically. However, the distinction between what people consider 'import' to mean vs whatuseactually does is important and describinguse std::io;as importingiois doing a disservice to users who then go on to get confused aboutmodandextern cratebecause those are the true import statements and they don't understand whyusedoesn't work instead.