Packages in programming languages

Introduction

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.

Identity

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.

Scope

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.

Compiler directives

Language like Rust can compile source code written in two different editions - more or less slightly different dialects through edition attribute.

Symbol autoloading

In Rust there is a build, include and exclude package attribute, in Python there is __path__ attribute is used during imports of its subpackages.

Exported symbol list

Used in JavaScript through export statement is used when creating JavaScript modules to export functions, objects, or primitive values from the module and Java through exports module directive specifies one of the module’s packages whose public types (and their nested public and protected types) should be accessible to code in all other modules in Python namespaced module __all__ attribute is used as a construct which instructs loading machinery which symbols to load.

Required modules / packages

In Rust it is possible to specify dependencies using package attribute, other languages like Java has a requires and requires transitive module directive.

Conclusion

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:

Packages in PHP - Syntax conception

August 12, 2019
Concept of Packages in PHP - idea and thoughts about the way of implementing them inside PHP
package module
comments powered by Disqus