Why is `using Module` used in Julia while `from module import *` is generally discouraged in Python?

There are two issues with from foo import * in Python:

  1. It makes it hard to figure out where the imported names came from
  2. It can potentially clobber existing names in your module or names from other modules you’ve imported

Issue (1) does apply, as you’ve noted, in Julia, but issue (2) does not. Doing using Foo will not clobber any of your existing types or functions (it will just require you to be specific and refer to any conflicting types as Foo.MyType instead of just MyType). For that reason, using Foo is less harmful than from foo import * in Python.

But I do agree that the convenience of using Foo should be balanced against the increased difficulty in reasoning about a piece of code. I generally try to avoid multiple plain using declarations in a given module, and instead try to prefer using Foo: my_method when I only need one or two names from a given module.

12 Likes