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

Allow for wildcard imports #676

Closed
Baccata opened this issue Dec 21, 2020 · 3 comments
Closed

Allow for wildcard imports #676

Baccata opened this issue Dec 21, 2020 · 3 comments
Labels
feature-request A feature should be added or improved.

Comments

@Baccata
Copy link

Baccata commented Dec 21, 2020

Related to #636, I'm finding myself having to copy a large amount of built-in traits (as well as trait providers / validators) to a namespace I control, in order to cater to my users' use case.

Whilst I don'y mind doing so, I think it'd be convenient to be able to import everything from a specific namespace :

use my.namespace.traits#_ 
@JordonPhillips
Copy link
Contributor

Generally the problem with wildcard imports is that you can never be sure what is defined and what isn't. There are two scenarios I'm worried about if we added this:

  1. Upstream adds a shape with a name that you already defined locally, which would cause a break since now two shapes of the same name are defined. We can work around this by preferring the local name, and requiring the fully qualified shape id for the upstream shape. You'll still break if you try to use both within a single service closure, but that's a modeling-time error.
  2. You define a shape with the same name as something upstream already has. If the upstream shape was already being used, then now you potentially have a breaking change that may not be discovered until runtime. This is of course assuming we add the conflict resolution described above.

@JordonPhillips JordonPhillips added the feature-request A feature should be added or improved. label Dec 28, 2020
@mtdowling
Copy link
Member

Given the problems called out by @JordonPhillips, and given Smithy models are often maintained in multiple packages owned by different teams, I don't think we can support wildcard imports.

The most significant issue is that if you use a wildcard import of another namespace, and the maintainer of that namespace adds a shape that conflicts with a shape defined your file, then you've got a build-time break due to the shape conflicts. This could be mitigated through some kind of cascading shape ID resolver, but that would add even more complexity to Smithy's shape ID resolution process (which currently has to account for forward references and the prelude).

The other key reason we avoided wildcard imports is that they hinder code search. With the current import syntax, you can search for shapes by their fully qualified ID because the fully qualified ID is in the model file. This allows you to use simple tools like grep to look for shapes. Wildcard imports means you need some kind of semantic grep.

@Baccata
Copy link
Author

Baccata commented May 12, 2021

I find the rationale satisfying, thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

3 participants