Some C++ developers strongly suggest to never use using namespace std
, as they prefer to explicitly include the namespace of every function in their code. Reasons for this include clarity when reading code as well as preventing shadowing definitions with equal identifier. According to Julia's documentation, all modules and types already contain using Base
(and other) statements, so fully qualified names are in practice not necessary. (There is a way to overrule this default behavior, though, as explained in the documentation.) Is there a style consensus among Julia programmers whether to use fully qualified names for Base
functions and types when writing modules? That is, for instance, writing Base.println(some_string)
vs println(some_string)
.
Is there a style consensus among Julia programmers whether to use fully qualified names for Base functions and types when writing modules?
The consensus is not to use fully qualified names.
Does Julia Base have that same issue?
No. Package developers are aware of names in Base
, and to not overshadow them.
See e.g. Blue Style guide.
There are there are many more style rules in the guide, but the relevant is:
Prefer the use of using over import to ensure that extension of a function is always explicit and on purpose:
# Yes: using Example Example.hello(x::Monster) = "Aargh! It's a Monster!" Base.isreal(x::Ghost) = false # No: import Base: isreal import Example: hello hello(x::Monster) = "Aargh! It's a Monster!" isreal(x::Ghost) = false
Which is a recommendation for package developers to extend Base Julia functions and not overshadow them. (which in turns means that you can safely use using
as a user)