On Sunday, 9 February 2014 at 19:12:21 UTC, Jeremy DeHaan wrote:
I am working on a library, and I put all imports at the top of my source files under the module declaration. I was starting to think that it might be a good idea to start scoping some imports to reduce the number that might be used by a giving project, but how beneficial is this? Are there any kind of general rules for when to use module level imports vs scoped imports?

Thanks!
     Jeremy

Use scoped imports as much as possible. Those are completely superior to global ones. Pretty much only reason to have something as global import is if it is used in template constraints or vast majority of functions/methods of the module.

Usage of selective imports is also encouraged.

Main benefits are lazy evaluation and simplified maintenance - unused import become obvious, as well as symbol origins in function bodies.

Reply via email to