David Rodenas PhD
1 min readMay 8, 2022

--

Do you mean Typescript Namespaces? ;)

A funny thing, the main problem of namespaces is that they are global variables: if you put something in one namespace, you need to be sure that no-one else put something in the same namespace.

Java solves this problem by using dns-like namespaces, so if you own the dns, no one may use the same namespace. Node solves it with a centralized registry (aka npm), once you register a library, no one else can register it.

The big problem of being global variables is not that others may overlap your global space, it is that you may overlap with yourself. Let me explain, imagine the libraries A and B that use C, but the A library uses C version 1, and B uses C version 2. Can you use A and B at the same time? The answer is not in Java, yes in JavaScript. Because the Node registry leverages in the JavaScript closure mechanism to avoid global namespaces.

That is why the npm ecosystem exploded so rapidly, meanwhile others like Java are harder to grow: Java libraries must be sure that they are inter-compatible between them, all the time.

--

--

David Rodenas PhD
David Rodenas PhD

Written by David Rodenas PhD

Passionate software engineer & storyteller. Sharing knowledge to advance our skills. Join me on a journey of discovery in the world of software engineering.

Responses (2)