I use Java where we only have packages. I know there are other programming languages that also include modules.
What's the difference?
Thanks
I use Java where we only have packages. I know there are other programming languages that also include modules.
What's the difference?
Thanks
It's hard to compare semantics in the void. (What other languages do you mean?) A "module" might be analogous to a Java class, or a Java package, or something else entirely, depending on that other language. Typically since "modules" tend to be from procedural languages, I'd lean toward saying Java class, but I think the line is very fuzzy at that point and you could argue package quite convincingly.
A package is more akin to a C++ namespace than a module. A module is more akin to an enclosing class than to a package.
instanceofTom's comment nailed it - Different languages have different definitions of package and module. Therefore there's no language agnostic answer to this question.
I'll try to answer it from the perspective of some of the languages I know:
Java: It has a concept of package
s, which are basically just a mechanism for organizing Java classes, interfaces etc into namespaces. They require hierarchical structure. package
s don't have first class status. It might also be worth noting that superpackage
s proposed for Java 7 are also sometimes referred to as module
s.
Modula: module
s, same in concept to Java's package
s. Don't require hierarchical structure.
C#: namespaces
, same in concept to Java's package
s. Don't require hierarchical structure.
C++: namespaces
, As the name indicates, these are just namespaces. Don't require hierarchical structure.
Haskell: module
s, same in concept to Java's package
s.
Scala: package
s in Scala are same as package
s in Java, except that they don't require hierarchical structures. A few more restrictions like one-public-class-per-file have also been relaxed. object
s in Scala are also referred to as modules, and they also enjoy the first-class status.
F#: namespaces
in F# are same as C# namespace
s. Besides namespace
s, F# also has modules
which are implemented at CLR level as .NET classes with static methods. They aren't first-class entities.