Namespace problems occur when names used in your code directly conflict with names used in existing code.  In the worst case the compiler will not be able to differentiate between the two definitions but usually it simply confuses other developers.  Whilst direct namespace conflicts are rare in Java thanks to the excellent package hierarchy concept, it is still a consideration for the developer, especially in technologies like JSP and Javascript where scope of a variable can be global.  For example, in a JSP there is often already a variable called “request” so it is not wise to also create a variable called “request”.  Another example is that .tag files will not allow attributes called “class” because it is a Java reserved word.

For naming of classes, don't choose misleading names that are already part of common Java libraries, like Event, Vector, List.

public class Event
{
   :
}

Imagine how many libraries and existing bodies of source code already use an Event class.  It would be wiser to use a more explicit classname to differentiate it from the hundreds of others:

public class PaymentEvent
{
   :
}

Javascript is even worse.  It's a fact of life that many Java developers roast their brains with Javascript from time to time.  In basic javascript all function and type names are global, so be wary of using Event at all, instead use something specific like PaymentEvent – wordy, but very clear.

blog comments powered by Disqus