-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only make exported bindings available with import
#12069
Comments
there seems to be a mixing of terms here. |
No, I'm arguing that there should be a construct which only makes the exported variables available through the fully qualified dot-syntax. Reiterating above example, package
now using this with, let's call it
But it was maybe a bit confusing as I suggested both The idea would be that |
If field overloading was allowed and But adding yet another variant of |
The problem exists also when you are doing specific imports, eg
works even though I agree that it should be possible to import things in a way that protects you from importing an unexported symbol by mistake, also when using the more disciplined alternatives to |
Restricting access to |
I like @nalimilan's suggestion, if the |
Would it be possible to chain the private symbols. I.e. that in the initial example |
As an alternative to |
I definitely want a way to be able to access the exported members – and only the exported members – using the module name as a namespace qualifier. This is to avoid PHP's massive global namespace, which leads to confusion as to what name comes from what module. |
Ping? This seems like a major problem for large-scale projects. Common Lisp solved it by separating |
Can I ask what is the status of this proposal? |
In case it helps.... the following Discourse comment provides and example of how to create private properties for a type. |
My (maybe wrong) understanding is that the public API of a package is what its main module
export
s.However, exports only impact when
using
a Package and not whenimport
ing. However, for larger scale software projects it is probably often preferable to useimport
to get the safety benefits of separate name-spaces. But this means that when I program in the "safer"import
-mode there is no easy way to tell whether I use the public API or some private feature. So, it's not really safer at all.I wonder whether it would make sense and be more consistent with
using
thatimport
only allows access to the exported bindings, and thatimportall
imports all the bindings (and also allows method extension, i.e. as it is now):(this needs more working out though)
This would be a breaking change but could maybe be done through depreciation warnings. Worth the hassle though?
Or could/should one write a
@safeimport
macro doing above?Related: #8000.
The text was updated successfully, but these errors were encountered: