Understanding namespaces

What is a namespace? Let's try a real-life example.

Every language has its own set of words as defined in its dictionary. When people from different cultures talk to each other, they often end up in amusing situations. Consider these examples:

Conversation 1:

  • American: Your pants look dirty. You should change them.
  • British: Do you mean my trousers? My underpants are... quite clean and well!

Conversation 2:

  • American: These biscuits are yummy!
  • British: Where? Where are the cookies...?

Conversation 3:

  • American: I want to get back in shape and have tried many trainers but none of them are good.
  • British: Have you tried the new running ones from Nike? I found them comfortable enough for my daily jogging routines.

In fact, you don't even need to be from a different culture to experience this problem. Sometimes the same word already has different meanings depending on the context. For example:

  • Pool - swimming pool or a group of things?
  • Squash - the vegetable or the sport?
  • Current - electrical current or a flow of water?

There is no way that we can enforce a single vocabulary across all domains because of ambiguities such as these. Fortunately, computer scientists are smart and long ago solved the problem as it pertains to their field: to distinguish two different meanings for a single word, we can just prefix the word with the respective context. Using the examples from the preceding list, we can qualify each word as follows:

  • Facility.Pool and Grouping.Pool
  • Vegetable.Squash and Sport.Squash
  • Electricity.Current and Liquid.Current

The prefix is known as a namespace. Now that the words are qualified with their respective namespaces, they are no longer ambiguous and have a clear meaning.

In Julia, namespaces are created using modules, which we will learn about in the following section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.186.109