-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add file-private require
#4368
Comments
Duplicate of #140. I don't think the core team's opinions have changed much. |
Hmm, it seems that the main issue mentioned in #140 was (from @asterite's comment): The The same monkey-patching "issue" (really a feature IMHO) also arises with
So the full Now suppose a file |
Another issue: the order of
and the library user uses two files dependency1.cr and dependency2.cr that
Now the user merely switches the order of the
This then leaves the user scratching his/her head, wondering why merely switching the order of the The above examples are perhaps a bit contrived, but hopefully illustrate why it would be useful to have And what if dependency1 and dependency2 above need to use different versions of the same Crystal library? Crystal does not allow this if restricted to the current |
tl;dr - but I think this is about a feature I'd die for to have in Crystal, I'll just add my wording, and then you shoot me if it was straying from the subject.
It would simply add the module namespace to "naked name lookups"-list within whatever narrow scope I choose (_for instance maybe within one branch of an if). That/those module(s) should then be removed from lookup-list when that scope ends. Needless to say then: without including it in mine, and polluting the namespace of my module. (If the user of my module also wants the features of a module mine is also using - they'll just include it for I don't want to expose 3rd party modules just to be able to use them without namespace qualification. If this is already possible, and I totally missed something here, I've been out of the loop to long, and I'm then also very happy. Please say it's so! :) |
@ozra What you propose above (a scope-private |
@ozra By the way, what you propose above is (sort of) available in the following form:
Now, if only something analogous were available with requiring files so that the global namespace didn't get polluted... :-) |
@asoffa - thanks for the sharing of tricks - I feel it's "all or nothing" though :) |
Closing as duplicate of #140. You may voice yourself in closed issues if you really have to, but plase don't duplicate issues. |
Hi,
Suppose I have a file that requires a large number of resources that are used for its internal behavior, e.g.
Now, any file that requires "sophisticated" will inherit the contents of all of the files a.cr, ..., z.cr that sophisticated.cr requires for its implementation and any requires within a.cr, ..., z.cr recursively. This can lead to code pollution, especially when there are modules, classes, etc. with similar names (and even redefinitions in the worst case if there are identical names). Therefore, it would be nice to have a new keyword (e.g.
use
) or some sort of marker forrequire
(e.g.private require
) so that the implementation details within sophisticated.cr are not leaked into files that merely use sophisticated.cr, e.g.On the other hand, the leaking behavior is sometimes desirable for e.g. splitting up a module across multiple files, so it would be nice to have both the current behavior of
require
and this proposed addition.This would be along the same lines as #3280, but for requiring files instead of defining modules, classes, constants, methods, etc.
Thoughts?
The text was updated successfully, but these errors were encountered: