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
[0.4.0] Import as #775
[0.4.0] Import as #775
Conversation
I have mixed fillings about that change. While I'm not particularly against "as" to be a new keyword, I don't find it particularly superior to:
I also think there is a little ambiguity that is introduced by using The |
See the test cases, the values are copied because the variable is loaded onto the stack and then stored into a slot, all this does is make the slot name different if as is present. mechanically there is no change. |
Ok so I'm not mistaken, the ambiguity is introduced by this change then. It is a minor issue thought, but I found it counter intuitive that this language choice can not convey the actual behavior. So the operator = usage here makes more sense to me as it enforce the idea of copying. But it may be only me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't find the copying (which is really just copying of the reference, most of the time) makes using as
confusing, but then I'm already used to this keyword from QML's import syntax.
While this change is useful to avoid ambiguity to a certain degree, I really hope that once we'd have the as
keyword we can eventually also make import "module" as M
syntax work, making the module's variables available using M.Variable
.
Co-authored-by: Thorbjørn Lindeijer <bjorn@lindeijer.nl>
Co-authored-by: Thorbjørn Lindeijer <bjorn@lindeijer.nl>
Note that |
It can be likewise decided to make To add to the cons, and comparing to C++, the |
I agree |
To clarify my words, I don't care about the choice of the |
import "..." for OtherName = Variable is less clear to me than import "..." for Variable as OtherName The first statement reads as "import this module so we can use OtherName to refer to Variable", while the second reads as "import this module to we can use Variable and call it OtherName". It's just more clear, and more conventional, and I don't see a real reason to use the assignment operator here |
It is the same reason to why
I read "Import this module, that give me this symbol followed by =" and I stop reading unless I really need to know what is the underlying type. If you import many symbols, you can do something like:
And the defined symbols is always visible at first sight, and does not require reading the whole expression, hacky text alignment or editor search. |
I have still found the ability to rename an imported variable vital over time.
I plan to introduce this in 0.4.0 with the
as
keyword. This PR replaces #464