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 upAllow multiple crates in one `extern crate` declaration. #167
Conversation
This comment has been minimized.
This comment has been minimized.
sinistersnare
commented
Jul 16, 2014
|
Thanks for writing this up, I have been meaning to myself. +1 for with or without braces. maybe for when we do |
This comment has been minimized.
This comment has been minimized.
sinistersnare
commented
Jul 16, 2014
|
Also: original issues rust-lang/rust#11811 and rust-lang/rust#11819 |
This comment has been minimized.
This comment has been minimized.
sinistersnare
commented
Jul 16, 2014
|
And final questions from that thread:
#![feature(phase)]
#[phase(plugin)]
extern crate regex_macros, collections;
/** These are glorious docs*/
extern crate foo, bar, baz; |
This comment has been minimized.
This comment has been minimized.
|
Doc comments attached to an extern crate statement are ignored in general. |
This comment has been minimized.
This comment has been minimized.
bharrisau
commented
Jul 16, 2014
|
Maybe I don't write enough (or use enough extern crates when I do), but I really don't feel like this change is worth it. Trying to jam several crates into one line makes it much less readable. I feel the biggest benefit is with |
This comment has been minimized.
This comment has been minimized.
|
Python is a language where you can do this sort of thing, but it is considered bad form—PEP 8 forbids |
This comment has been minimized.
This comment has been minimized.
|
@bharrisau @chris-morgan You don't gain anything by copying |
This comment has been minimized.
This comment has been minimized.
bharrisau
commented
Jul 16, 2014
|
@liigo Maybe it is just me, I just have a harder time scanning
|
This comment has been minimized.
This comment has been minimized.
lucy
commented
Jul 16, 2014
|
Using extern crate {
foo,
bar,
baz,
};natural, which currently works with |
This comment has been minimized.
This comment has been minimized.
|
Harris, we always read articles/words from left to right, I don't think |
This comment has been minimized.
This comment has been minimized.
sinistersnare
commented
Jul 16, 2014
|
@lucy Why should the following not work? extern crate foo,
bar,
baz,
qux;
|
This comment has been minimized.
This comment has been minimized.
lucy
commented
Jul 16, 2014
|
@sinistersnare It does, but doesn't read as well (in my opinion), or like any other things in the language (as far as I know). The form with braces would be closer to other "lists" like structs, enums and use statements. Allowing a comma after the last crate in that—so that inserting, removing and reordering crates can be done easily—also seems problematic. |
This comment has been minimized.
This comment has been minimized.
DiamondLovesYou
commented
Jul 19, 2014
|
+1 for extern crate { foo = "bar", bar = "foo" };I feel this could be delayed till post-1.0, though. |
This comment has been minimized.
This comment has been minimized.
sinistersnare
commented
Jul 20, 2014
|
If someone else can implement it who is not on the core team, why postpone it. |
This comment has been minimized.
This comment has been minimized.
pczarn
commented
Jul 20, 2014
I can remember research that has found narrow columns of text (as in newspapers) to be easier to read. Even though they aren't optimal in terms of average reading speed. a weak -1 |
This comment has been minimized.
This comment has been minimized.
The current Rust code style for column limit is 100, you can narrow it to 80, even 40. That is just another topic. When I extern 8 crates in one line, it just 73 columns:
and you are free to rewrite it:
|
This comment has been minimized.
This comment has been minimized.
|
+1 For the |
This comment has been minimized.
This comment has been minimized.
bharrisau
commented
Jul 31, 2014
|
Is there some compelling reason for this change that I'm not seeing? Given the interactions with extern crate renaming, and the general 'expense' of having an external dependency, this feels like a solution in search of a problem. There is no consistency issue with |
This comment has been minimized.
This comment has been minimized.
|
To make it more consistent and clearer, is the reason. This change do Is there some compelling reason to keep verbose and non-consistent? |
This comment has been minimized.
This comment has been minimized.
|
@bharrisau: While its true that you never write many
The main difference is that
But in both cases its the same operation: "Take this name, and make something in the local scope reachable through it". For Weaker differences are
|
This comment has been minimized.
This comment has been minimized.
bharrisau
commented
Aug 7, 2014
|
Except we also have But it is a minor issue - I do believe it will do more harm than good, but I'm not going to kick and scream about it either way. |
This comment has been minimized.
This comment has been minimized.
|
Heh, true, there are quite a few more differences than common properties between those two item types. :) However, those lay in the side effects or source of the elements referenced. What they have in common is the effect on the current module, which, like the syntax, is what the developer of the module actually has to work with. As an example, the two lines in mod foo {
extern crate {core, regex};
use {mycore, myregex};
}
mod mycore;
mod myregex;
That said, this is a purely backwards-compatible change, so I wouldn't be surprised if this does not get decided on one way or another before 1.0, and till then a lot can still change that could change my reasoning here. |
This comment has been minimized.
This comment has been minimized.
|
This is a minor feature without a lot of agreement about whether it's desirable, and since it's backwards compatible, we want to not do it now. If it continues to be a pain point we can revisit. |
liigo commentedJul 16, 2014
Summary
Allow multiple crates in one
extern cratedeclaration.Motivation
To make the source code more compact, and be consistent with
usedeclaration, which allow use multiple types/functions in one line (one declaration).Detailed design
Instead of having to write:
... the programmers could be allowed to write these in one line:
The new syntax EBNF would be:
After this change, the source code is more compact, but still keep clean, concise and readable.
Drawbacks
Lexer syntax will be a little more complex.
Alternatives
Use the
{ }syntax ofusedeclaration:which is a little fussy.
Unresolved questions
None.