-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
Currently, we don't have a way to make names private. The convention is to prepend _ to the name. But this is just a convention, which users can and do ignore.
Omitting how and why the inability to make names private can ruin everything in large codebases, I propose to add private keyword for making names private that is analogous to export. So something, which currently written as
module Mod
export a, b
a(x) = _a(x)
b(x) = _b(x)
_a(x) = ... # internal implementation
_b(x) = ... # internal implementation
endwould be written as
module Mod
export a, b
private c, d
a(x) = c(x)
b(x) = d(x)
c(x) = ... # internal implementation
d(x) = ... # internal implementation
endand c and d would not be accessible outside the module. This also makes the code more clean and readable (without hairy names starting with _), which is something that Julia generally strives for. This way we would have 3 kinds of names:
- truly public names (i.e.
exported) - public names that are accessible with module name (default option)
- private names that are not accessible outside the module
I have no knowledge of compiler, but I would expect that this can also enable some compiler optimizations that otherwise are not possible.