-
-
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
namespaces / modules #57
Comments
What happened to the old wiki page that had some design ideas for this? |
It's still there: https://github.com/JuliaLang/julia/wiki/Modules. |
I really don't yet feel the need for these. I hate using scipy for this exact reason. For every function, you have to go hunting through the modules and importing them, and I can't every remember the order in which to go, and the syntax to use. Its always 5 mins before I can do any realistic computation. What if we just allow function names to have a dot in them? Then people can just use a naming convention to make it look like a namespace, without really having true namespaces. |
I agree that we don't need it just yet, but we will eventually. That's why this is tagged v2.0 :-) I think that there is a happy medium to be found with namespacing. All languages seem to be too far on one side or the other: either there are no namespaces like C and Matlab, or there are namespaces and half of your code is incredibly annoying import statements like Java or Python. Having to import something to use println is idiotic. One big issue is just granularity of namespacing. If modules are fairly big, then you can just do something like
or whatever. I also think that scripts and modules should have different defaults — when you start writing code to run in the repl or a script, you don't want to have to mess around with imports, but when you're writing a module, it makes sense to be a bit more explicit about what you're using. And finally, it's really annoying to have to import something just to use it. If you explicitly call something by its full name, it should always be available. If I call |
Agree! Modules are more of a feature, rather than a way to structure the whole system. They are for getting around the problem that all the good names are taken. There are certain interesting use cases, e.g. if you start writing your own libm replacement entirely in julia, you want to be able to name functions sin, cos, etc., and then be able to call both system.sin and mystuff.sin and compare them. And then to switch an application to using the new code you want to just add "import mystuff: *" at the top. Stuff like that. I also like the idea that you don't need to think about modules until you start writing one yourself. You start in an environment where everything is generally available and modules have already been imported. If you have more specific needs and want to control what's imported, you write a module and it starts totally empty. Seems ideal to me. |
I think modules are a must for people that write specialized libraries or even just reusable code that would be shared widely. Also, it is a nice way to avoid name clashes. That is the one of the major things that holds octave back vs MATLAB. Moreover, modules could, in principle, be (pre) compiled separately like in Python. |
Definitely agreed that it's something we need. Just hasn't yet become pressing and there's so much to get done. I think the precompiled units and namespaces are somewhat orthogonal. Compiling files as units probably makes sense, regardless of namespaces. Languages like Java and to some extent Python conflate these two because files correspond to both classes (i.e. user-defined types) and namespaces, all of which are natural compilation units. But without the file-class-namespace identification, these mappings are no longer so obvious. Especially in the presence of multiple dispatch, there's no obvious way to make classes/types correspond to compilation units. |
I won't even pretend to know what multiple dispatch is or what it is useful for, so I will defer to you on that topic and how it complicates modules. |
Multiple dispatch is actually simple enough: the implementation of Anyway, welcome. We're glad you're checking Julia out :-) |
Commit 30bdf1c takes the first tentative step. |
As somebody wanting to write reusable code, modules are pretty important to me. This is something that drives me nuts with matlab. As far as a model to pick: I'm kind of a fanboi, but I like the commonjs/node module system, and it's one I would draw inspiration from over python's. The only downside is when you have to require basic shit in the repl, imo. |
Namespaces are your best friends. One of the problem with R is that it will behave differently depending on which packages/librarie you have loaded. Explicit/absolute names have also the advantage that when you read some code, |
(con'td) But then, even by specifying the fully qualified name reshape2::melt, is still does not work, because internally reshape2::melt makes use of sub functions My point: just as in perl or jav, packages/libraries should not export symbols unless explictely requested to do so. If you want to have a robust package eco-system, I do not see another way. |
@kforner you should explicetly import it from reshape2. Namespaces and package system in R are simple and very flexible. I don't know much about Julia (as yet), but whoever develops namespaces for Julia should definitely look into R's system. |
Given all of the overlap in ideas between Julia and Dylan, you probably know about this already, but it might be worth taking a look at the Dylan module system: http://opendylan.org/books/drm/Program_Structure My guess based on some comments here is that as a whole you'll find it too heavy-weight for Julia, but maybe it will be a useful reference point. |
Thanks, @cgay. This is very useful. I'll read through how Dylan handles this. We may want something a bit simpler/dumber, but the problems the two languages have are so similar, it would be a crime not to consider Dylan's approach when designing this. |
It would be nice if we can have embed docs (like perl and ruby does) in modules. |
How's this for a solution: Use a spaghetti stack of globals (including function and type names). The Note that this is very similar to how another common dynamic execution framework works: Unix shells. I can Different folks might try to use the same script over and over in different levels of the stack, so you'd want to optimize already having it parsed and semianalyzed, but you'd have to rework the dispatching and type specialization in some cases. With cleverness, maybe that reworking could also be kept to a minimum. A version of use do
function blah ...
end Or something like that. I just discovered Julia yesterday (literally), so I might have some details on various issues not quite down exactly. |
Module system now available. |
The module system is not yet documented in the manual ( http://docs.julialang.org/en/latest/manual/ ), but rather listed as a "Potential feature". |
Add compat for unsafe_convert
* Add v0.6-alpha to Travis tests; remove v0.5.0 test * Allow failures for v0.6-alpha build
We're still unclear on how they would work, but we probably will want to have modules or namespaces at some point.
The text was updated successfully, but these errors were encountered: