views:

38

answers:

1

I've been researching how different languages manage organization of source code. It appears most modern languages use some form of named abstract container. What its called and how its implemented varies from one language to the next but it boils down to a programming construct that operates beyond file boundaries to group related code.

In Java and .NET languages it is used as the basis for organizing dependencies (You include/import the namespace/package a class belongs to rather than the file it is defined in). While C++ uses it only for avoiding name clashes.

I'm curious as to who first proposed this idea and when was it proposed. Also which language was the first to implement it?

A: 

Namespaces and modules are separate concerns. Namespaces provide separate conceptual grouping of identifiers. If project A uses namespace A and all its identifiers are in A or subnamespaces of A, then it cannot clash with project B using namespace B. In a language with one big flat namespace such as C, problems can occur when different projects want to use the same identifier.

Modules are individual units of code. Generally they are files or groups of files, though I don't think a strict definition is possible. Modules can contain submodules which contain submodules.

The difference here is that while it is common for each module to have its own namespace in a one-to-one relationship, it's not required in general. For example, the C++ STL is divided into different modules such as <vector>, <functional> etc but they all use the same namespace std::. In C, you can have modular code (in .c/.h pairs) but you can't have namespaces - or equivalently, all modules use one namespace.

The name "package" in general can be ambiguous: I have seen it refer to either a namespace (as in Perl), or to a namespace/module combination (as in Java).

Philip Potter
So they are distinct concepts. Java and .NET killed two birds with one stone by combining namespaces and modules into a single construct. Good to know. This still doesn't begin to answer my original question which was: Who invented namespaces? Who invented modules? When were they first implemented in a language?
codeelegance
@code: I didn't answer that part because I didn't know :) I imagine modules are almost as old as subroutines, and with their fuzzy definition difficult to trace exactly. Namespaces don't seem to appear in 1950s and 60s languages such as fortran, lisp, algol; C++ and Perl both acquired their namespace features in the 1990s; so there's a lower and upper bound for their invention (or at least popularisation).
Philip Potter