modules and encapsulation #43
RupertAvery
started this conversation in
General
Replies: 1 comment
-
|
I'm already planning to implement access modifiers, also for module level |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I think modules should have encapsulation.
When you
importandusinga module, you allow name resolution to bubble up to the imported module.If the module has many variables, this may cause collisions in the calling module. The more modules you import, the more it becomes a problem.
classes and functions are less of a problem than variables. And sometimes you don't want to expose module variables to importers, because you are just using them in your module.
I suggest we add an
publicmodifier at the module level to control what methods, classes and variables are accessible from other modules. If not specified, any declaration should be private.In TypeScript modules, the equivalent is
export.In Go, encapsulation is controlled by the case of the first character of a type, class or function. lowerFirstCase = private, UpperFirstCase = public
Example
Beta Was this translation helpful? Give feedback.
All reactions