You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-dev@incubator.apache.org by James Margaris <jm...@nexaweb.com> on 2006/06/23 16:56:04 UTC
IMPORTANT javascript naming convention
Currently the code checked in is not a part of any namespace and is not
prefixed with anything. We need some way to make sure our names don't
collide with other names. (For example our Hashtable is going to collide
with any other Hashtable class)
Typically the way this is done is either with a prefix like XapHashtable
or with a "namespace" like org.apache.xap.util.Hashtable.
Prefix approach:
Pros: Smaller code size, easier to type in.
Cons: For large codebases doesn't divide code into logical units.
Namespace approach:
Pros: Divides code into logical packages. Works with auto-complete in
some Javascript editors.
Cons: Larger code size. Unlike in Java you can't import a package and
use items from it, you have to refer to them by the full package name
every time you create a new one. So you would have to do: new
org.apache.xap.util.Hashtable(). This can get pretty verbose, and be a
pain to type in and also make the code larger.
So I think there are two questions here.
1: What is the preferred approach.
2: For the preferred approach, what is a reasonable namespace/prefix?
My opinion is that a namespace approach is a lot more scalable and
helpful for large projects, which this is. From there I would say
org.apache.xap or simply xap as the base namespace makes sense.
My preference purely from a coding perspective would be simply xap as it
will make the code a bit smaller and more manageable. Unlike in java the
namespace being "com.XXX" or "org.XXX" is not a standard or a de-factor
standard. Yahoo simply does YAHOO.xxx and Dojo does dojo.xxx.
I'm not how acceptable it would be to have Apache APIs that are don't
begin with org.apache, maybe someone with more experience can speak to
that.
This would be a good thing to resolve quickly because changing it all
later is going to be more and more painful as more code is added.
Again to summarize, my preference would be a namespaced approach with
"xap" as the namespace root rather than "org.apache.xap"
Opinions?
James Margaris
Re: IMPORTANT javascript naming convention
Posted by Martin Cooper <ma...@apache.org>.
On 6/23/06, James Margaris <jm...@nexaweb.com> wrote:
>
> Currently the code checked in is not a part of any namespace and is not
> prefixed with anything. We need some way to make sure our names don't
> collide with other names. (For example our Hashtable is going to collide
> with any other Hashtable class)
>
> Typically the way this is done is either with a prefix like XapHashtable
> or with a "namespace" like org.apache.xap.util.Hashtable.
>
> Prefix approach:
> Pros: Smaller code size, easier to type in.
> Cons: For large codebases doesn't divide code into logical units.
>
>
> Namespace approach:
> Pros: Divides code into logical packages. Works with auto-complete in
> some Javascript editors.
> Cons: Larger code size. Unlike in Java you can't import a package and
> use items from it, you have to refer to them by the full package name
> every time you create a new one. So you would have to do: new
> org.apache.xap.util.Hashtable(). This can get pretty verbose, and be a
> pain to type in and also make the code larger.
>
> So I think there are two questions here.
>
> 1: What is the preferred approach.
> 2: For the preferred approach, what is a reasonable namespace/prefix?
>
> My opinion is that a namespace approach is a lot more scalable and
> helpful for large projects, which this is. From there I would say
> org.apache.xap or simply xap as the base namespace makes sense.
>
> My preference purely from a coding perspective would be simply xap as it
> will make the code a bit smaller and more manageable. Unlike in java the
> namespace being "com.XXX" or "org.XXX" is not a standard or a de-factor
> standard. Yahoo simply does YAHOO.xxx and Dojo does dojo.xxx.
>
> I'm not how acceptable it would be to have Apache APIs that are don't
> begin with org.apache, maybe someone with more experience can speak to
> that.
>
> This would be a good thing to resolve quickly because changing it all
> later is going to be more and more painful as more code is added.
>
> Again to summarize, my preference would be a namespaced approach with
> "xap" as the namespace root rather than "org.apache.xap"
>
> Opinions?
I'm with you on both counts. The namespace approach is much more scalable,
and also allows for automated package management, which would be much harder
to do with a prefix approach. For example, Dojo's 'provides' and 'requires'
mechanism is *very* cool, especially since you can use it for your own code,
and for defining profiles, etc. I'm also fine with 'xap' as the root
namespace. I don't think there's any requirement to add 'org.apache' to
that, just for the sake of it.
BTW, although it's not my favourite construct, you can often use
JavaScript's 'with' construct if you _really_ want to shorten the code. On
the other hand, if you use a compressor (e.g. Dojo's ShrinkSafe), then it's
only an issue with writing the code, which, as you say, several editors will
help you out with anyway.
--
Martin Cooper
James Margaris
>
Re: IMPORTANT javascript naming convention
Posted by Igor Kaplansky <ib...@yahoo.com>.
Good ol' James, trying to pick the best of both
worlds.
I am with you buddy.
--- James Margaris <jm...@nexaweb.com> wrote:
> Currently the code checked in is not a part of any
> namespace and is not
> prefixed with anything. We need some way to make
> sure our names don't
> collide with other names. (For example our Hashtable
> is going to collide
> with any other Hashtable class)
>
> Typically the way this is done is either with a
> prefix like XapHashtable
> or with a "namespace" like
> org.apache.xap.util.Hashtable.
>
> Prefix approach:
> Pros: Smaller code size, easier to type in.
> Cons: For large codebases doesn't divide code into
> logical units.
>
>
> Namespace approach:
> Pros: Divides code into logical packages. Works with
> auto-complete in
> some Javascript editors.
> Cons: Larger code size. Unlike in Java you can't
> import a package and
> use items from it, you have to refer to them by the
> full package name
> every time you create a new one. So you would have
> to do: new
> org.apache.xap.util.Hashtable(). This can get pretty
> verbose, and be a
> pain to type in and also make the code larger.
>
> So I think there are two questions here.
>
> 1: What is the preferred approach.
> 2: For the preferred approach, what is a reasonable
> namespace/prefix?
>
> My opinion is that a namespace approach is a lot
> more scalable and
> helpful for large projects, which this is. From
> there I would say
> org.apache.xap or simply xap as the base namespace
> makes sense.
>
> My preference purely from a coding perspective would
> be simply xap as it
> will make the code a bit smaller and more
> manageable. Unlike in java the
> namespace being "com.XXX" or "org.XXX" is not a
> standard or a de-factor
> standard. Yahoo simply does YAHOO.xxx and Dojo does
> dojo.xxx.
>
> I'm not how acceptable it would be to have Apache
> APIs that are don't
> begin with org.apache, maybe someone with more
> experience can speak to
> that.
>
> This would be a good thing to resolve quickly
> because changing it all
> later is going to be more and more painful as more
> code is added.
>
> Again to summarize, my preference would be a
> namespaced approach with
> "xap" as the namespace root rather than
> "org.apache.xap"
>
> Opinions?
>
> James Margaris
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com