Are namespaces packages?

17 views (last 30 days)
David Young
David Young on 22 Jan 2025
Commented: David Young on 22 Jan 2025
The R2024a release notes say "The MATLAB language feature known as a package is now called a namespace."
The R2024b release notes say "A package is a collection of MATLAB code, related files, and a package definition file that defines the package identity and dependencies."
So I wanted to check: is the package referred to in the R2024b notes a new kind of thing, different to a namespace, or is the terminology change from R2024a being ignored?

Accepted Answer

Steven Lord
Steven Lord on 22 Jan 2025
It is a new thing.
namespaces
The + directory hierarchy that used to be called packages are now called namespaces, so using an example from the unit testing framework the TestCase class (matlab.unittest.TestCase Class) is in the unittest namespace inside the matlab namespace. But TestCase is not part of any package. See this documentation page for more information about namespaces.
packages
A package, going foward, is as you (and the documentation) said: it's a collection of (hopefully thematically related) software files that also lists what it depends upon (and can be depended upon in turn by other packages.) So you could have a collection of functions related to astronomical calculations in an Astronomy package, but in order to use that you need to have a Physics package installed. So the Astronomy package would declare a dependency on the Physics package, meaning when you install Astronomy it would check if Physics is installed and install it if it is not.
The package could contain functions that are not in any namespace (like sin, plot, etc.), functions inside a namespace included as part of the package (like the Physics package could include a function computeGravitationalForce to compute the force of gravity between two objects given their masses and distance apart), or both.
See this documentation page for more information about creating and working with packages.

More Answers (0)

Categories

Find more on Source Control in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!