In classic Prolog systems, all predicates are organised in a single namespace and any predicate can call any predicate. Because each predicate in a file can be called from anywhere in the program, it becomes very hard to find the dependencies and enhance the implementation of a predicate without risking to break the overall application. This is true for any language, but even worse for Prolog due to its frequent need for‘helper predicates’.
A Prolog module encapsulates a set of predicates and defines an interface. Modules can import other modules, which makes the dependencies explicit. Given explicit dependencies and a well-defined interface, it becomes much easier to change the internal organisation of a module without breaking the overall application.
Explicit dependencies can also be used by the development
environment. The SWI-Prolog library library(prolog_xref)
can be used to analyse completeness and consistency of modules. This
library is used by the built-in editor PceEmacs for syntax highlighting,
jump-to-definition, etc.