If you’re unfamiliar with what a namespace is then it may seem like a complex and abstract concept. At least it did to me when I first heard the term. But it’s really quite simple: a namespace is just a way of differentiating between names.

Take the example of how people used to introduce themselves, “I am William of Sparkumbria.” Which differentiates him from William of Haloburo. This really is a namespace because it’s differentiating individuals based on the location of their home. And within Sparkumbria someone named William might introduce himself as, William of System street to differentiate himself from William of Graphics street.

You can certainly see that there must be some way of absolutely identifying individuals or else there would be big trouble. If two, or more, individuals had the same identification then chaos would ensue. Wives would sleep with the wrong men. Children wouldn’t know who their father was. Madness!

In the programming world you might have two packages that do similar things. Take for instance GoogleMaps API ( Application Program Interface ) and YahooMaps API. You would expect that both would likely overlap a few times with method and property names. Both probably have properties such as latitude, longitude, altitude, etc. and method names such as getAddress(), getDirections(), etc. But that isn’t a problem because each package is located within their own namespace: googleMaps and yahooMaps. You could use both APIs in the same application – why you would want to is beyond me but you could – because each resides in it’s own namespace.

Namespaces were recently a hot topic in the Flex world because Flex 4 is a complete rewrite of all the Flex components and their architecture. Initially the plan was to put the new components in the same namespace – MX – as the old Flex 3 components. I know what you’re thinking, “Then how would we differentiate old Flex 3 Button from new Flex 4 Button?” Answer: prepend fx before all of the new components. So then we’d have <mx:fxButton />.

Yes, you’re right that would be crap and the Flex community let Adobe know about it. Fortunately the Flex development team listened and changed the code by making an entirely new namespace for all of the Flex 4 goodies called spark. Now the Flex 4 Button will look like this: <s:Button />.

Check out the links below for more information on the topic.

What do you think?