Modules vs. packages
Release 2.0 of Mosel introduced the possibility to write libraries for Mosel directly in the Mosel language, such a library is called a package. Packages are used from a Mosel model in exactly the same way as modules, namely by specifying their name in a uses statement. However, from the implementation and functionality points of view the two ways of writing Mosel libraries are not the same and the choice between packages and modules depends largely on the contents and intended use of the library. In some cases it may be convenient to split the implementation of a library into two parts, one as a module and the other as a package. If a module and a package on the specified DSO path have the same name, the package will be loaded by Mosel.
The following list summarizes the main differences between packages and modules.
- Definition
- Package
- library written in the Mosel language
- Module
- dynamic library written in C that obeys the conventions of the Mosel Native Interface
- Package
- Functionality
- Package
- define
- symbols
- subroutines
- types
- define
- Module
- extend the Mosel language with
- constant symbols
- subroutines
- operators
- types
- control parameters
- IO drivers
- extend the Mosel language with
- Package
- Efficiency
- Package
- like standard Mosel models
- Module
- faster execution speed
- higher development effort
- Package
- Use
- Package
- making parts of Mosel models re-usable
- deployment of Mosel code whilst protecting your intellectual property
- Module
- connection to external software
- time-critical tasks
- definition of new I/O drivers and operators for the Mosel language
- Package
With every module example in this manual we shall discuss the possibilities of implementing similar functionality as a package. For a detailed introduction to writing packages the reader is refered to the chapter 'Packages' of the Mosel User Guide.