Packages in programming languages
With modular programming, concerns are separated such that modules perform logically discrete functions, interacting through well-defined interfaces.
The module / package concept is formally supported by wide range of programming languages but many of them support package / module concept in different ways.
Some encapsulates symbols around single file, like for eg. Rust, Python; other encapsulates symbols around wider scope like Java encapsulates modules around Java Package.
There are few key aspects around programming language support for module / package concept.
Some languages use package name while resolving used / imported symbols, some not. In Rust package name used by Cargo tool doesn’t mean anything while in Python and Java it is a part of symbol name used while resolving symbols.
There are programming languages differentiate meaning of module and package, in Python scope of module is a single file while in Java module adds a higher level of aggregation above packages - which are directory / namespace scoped units, in Rust single package is one or more crates that provide a set of functionality, crates are library or binary and consist of modules.
Exported symbol list
and Java through
module directive specifies one of the module’s
public types (and their nested
types) should be accessible to code in all other modules
in Python namespaced module
attribute is used as a construct which instructs loading machinery which symbols to load.
Required modules / packages
Following above list of package / module key aspects might want to think of adopting similar concept in PHP.
At first what can benefit could potentially be:
- identity as a part of FQCN which allows identitying membership to explicit package;
- scope aggregating symbols with namespaces and in root package namespace;
- compiler directives this is the place where
declaredirectives should exist;
- symbol autoloading could potentially be a good start point in restructuring current autoload machinery adding support for other non-class symbols;
- exported symbol list this potentially is far future which could help providing package symbols visibility;
- required packages also far future, currently fulfilled by Composer Packages;