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)
.
Asked
Active
Viewed 109 times
1

JustLearning
- 1,435
- 1
- 1
- 9
-
1Julia is not C++. The C++ `std` namespace is full of gazillions of symbols, many of which have very short, common names. The chance of a collision is quite high, and the chance of a collision causing silent problem now-or-in-the-future is significant enough so as to warrant being selective rather than permissive. Does Julia `Base` have that same issue? – Eljay Sep 14 '22 at 20:19
-
Seems Opinion based. – Jason Sep 15 '22 at 06:50
1 Answers
1
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.
Edit
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)

Bogumił Kamiński
- 66,844
- 3
- 80
- 107
-
Thanks! Are the any citations or blogs/discourse to support these answers? Before posting my question, I couldn't find anything. – JustLearning Sep 14 '22 at 22:17
-
1The easiest thing to verify this is to look at the source code of packages. – Oscar Smith Sep 14 '22 at 23:16
-
Looks like at least the SciML developers tend to follow the conventions mentioned in the answer. Good enough to me. – JustLearning Sep 15 '22 at 01:03
-