Skip to content
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

Shorthand for same-named "as" clause #4

Open
seaneagan opened this issue May 21, 2015 · 6 comments
Open

Shorthand for same-named "as" clause #4

seaneagan opened this issue May 21, 2015 · 6 comments

Comments

@seaneagan
Copy link

It's quite common to import a library using the same prefix as the last segment of the library's name. It would be nice to have a shorthand for doing this:

import <foo>;
import foo.<bar>;
import dart.<async>;

as shorthand for:

import foo as foo;
import foo.bar as bar;
import dart.async as async;

Alternative syntaxes:

import (foo);
import foo.(bar);

(too similar to a function call?)

import [foo];
import foo.[bar];
import {foo};
import foo.{bar};

(too similar to destructuring?)

@lrhn
Copy link

lrhn commented May 22, 2015

Another option:

    import *foo;
    import foo.*bar;

@sigmundch
Copy link
Owner

yet another option:

import *foo*;
import foo.*bar*;

@seaneagan
Copy link
Author

I wonder if the * would be confused as a "wildcard", which feels would work in the opposite direction:

import foo; // `foo` prefix
import *foo; // "wildcard" import, no prefix.

@munificent
Copy link

All of those look awfully "punctuation-ey" to me. How about one of:

import foo.bar as;
import as foo.bar;

Either way, I think it might be better to consider this a separate proposal. I think it's easier to us to adopt small bits of sugar at a time, instead of large doses.

@seaneagan
Copy link
Author

All of those look awfully "punctuation-ey" to me.

Normally I prefer keywords too, but in this case the punctuation accentuates that the identifier is being used both to quality the location of the library as well as specify the prefix.

import foo.bar as;

It could work for traditional imports too:

import 'package:foo/bar.dart' as;
import 'dart:core' as;

but it reads like an unfinished / incomplete sentence to me.

import as foo.bar;

looks like the prefix is foo.bar, not bar.

@sigmundch
Copy link
Owner

... but it reads like an unfinished / incomplete sentence to me.

Same here. Yet another variation, use parenthesis with 'as':

import (as foo).bar;
import foo.(as bar);

Either way, I think it might be better to consider this a separate proposal. I think it's easier to us to adopt small bits of sugar at a time, instead of large doses.

I agree, let's keep this as something separate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants