Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

75%
+4 −0
Q&A What does "namespace" mean?

A namespace is a category to which a name can belong. Think of family names for people: I may be friends with several Jims, and if only one of them is present I can just call him Jim. But if multip...

posted 12mo ago by r~~‭

Answer
#1: Initial revision by user avatar r~~‭ · 2023-12-02T08:37:31Z (12 months ago)
A namespace is a category to which a name can belong. Think of family names for people: I may be friends with several Jims, and if only one of them is present I can just call him Jim. But if multiple are present, I can disambiguate which I mean by saying Jim Jones or Jim Smith. ‘Jones’ and ‘Smith’ are namespaces which can both contain the name ‘Jim’, and thanks to them the name ‘Jim’ can be used by two different people without ambiguity.

In programming languages, sometimes types, variables, functions, labels (thing you can `goto`), struct fields, etc. all belong to distinct namespaces—if I write `foo(a, b);`, a compiler or interpreter might know to look for `foo` in the function namespace and ignore any variables or types that are also named `foo`. Python doesn't do this; variables and functions (and types, when using type annotations) are all looked up in the same namespace.

Programming languages also often have a concept of a ‘module’ or a ‘package’, which is another way to create namespaces. Python does have these, of course; I can define a function `foo` in module `wibble`, and you can define a function `foo` in module `babble`, and a user can disambiguate them by importing the modules and writing `wibble.foo` or `babble.foo`.

This is not an exhaustive classification; other types of namespaces are possible, but these are two of the most common.

A namespace may or may not have a run-time representation. Python modules do, but the term/type/etc. namespaces in languages like C and Haskell don't, nor do the module-like namespaces in Java and C#. As an abstract concept, the only important quality of a namespace is the ability to use the same name to mean different things in different contexts without ambiguity.