Namespaces & Why You Should Use Them
November 6th, 2007If you don’t already know about Namespaces, Here’s a quick primer.
A namespace is a unique identifier for a particular library or collection of objects. Namespaces are used to prevent conflicts between various libraries and to simplify debugging.
Traditionally Namespaces are defined using the unique name of a given project or library followed by a subsequent functional grouping i.e. (Yahoo.Util). There is also a tradition from the Java community of defining namespaces & packages using reverse URL notation i.e. (com.ajaxbestiary.libraryname) I’ve found this notation to be too cumbersome for most Ajax projects.
Abbreviating Namespaces
Some developers prefer to abbreviate namespaces using a shorthand variable notation ie (var yu = Yahoo.Util). This technique should be used quite carefully as it can lead to conflicts and confusion in multi-library & multi-person development. My recommendation is that any abbreviations be standardized upon across all development within an organization.
Over the next few days I will be exploring the use of namespaces in common Ajax toolkits.


Previous Post
Next Post

Leave a Reply