pseudo-namespacing in JavaScript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Michaux

    pseudo-namespacing in JavaScript

    [from <URL: http://groups.google.c om/group/comp.lang.javas cript/msg/825bb682f5f456a 5>]

    On Feb 18, 11:02 pm, David Mark <dmark.cins...@ gmail.comwrote:
    On Feb 19, 1:14 am, Peter Michaux <petermich...@g mail.comwrote:
    Actually I think that FORK_addListene r is less likely to be clobbered
    than FORK. It's all a crap shoot with this single global namespace
    But if you have hundreds of targets instead of one, then the
    probability of collisions is increased. I do see your point that
    "FORKINGLEAVETH ISALONE" would be a less likely candidate for an
    overwrite.
    I've been thinking about this more for a library API.

    prefix namespacing

    FORK_addListene r

    vs.

    object namespacing

    FORK.addListene r

    It seems only one level of namespacing is every necessary for a
    library. If that is the case why use an object for this namespacing
    than just a prefix? Are there any useful benefits?

    Accessing FORK_addListene r is faster than accessing FORK.addListene r.
    I did do some tests on this sort of thing and I can resurrect the
    results if anyone is interested. The important impression I was left
    with was that doing tens or hundreds of thousands of identifier
    resolutions were in the range of 40 to 60 ms. I would say speed is not
    really a deciding factor.

    Looping over the API properties of the library is easier but I don't
    know why I would need to do that. I never have done that. With the
    prefix version it is possible to loop over the properties of the
    global object and do a regexp test on the property name. It wouldn't
    be quite as fast but it wouldn't be brutal.

    I suppose it does simulate Java namespacing syntax but that is hardly
    a reason to do anything.

    How did the object namespacing become so popular? Is it because the
    MM_ functions were so badly written and prefix namespacing got a bad
    reputation?

    Peter
  • Randy Webb

    #2
    Re: pseudo-namespacing in JavaScript

    Peter Michaux said the following on 2/22/2008 2:38 AM:
    On Feb 21, 10:34 pm, RobG <rg...@iinet.ne t.auwrote:
    >On Feb 22, 3:27 pm, Peter Michaux <petermich...@g mail.comwrote:
    >
    [snip]
    >
    >>prefix namespacing
    >>FORK_addListe ner
    >>vs.
    >>object namespacing
    >>FORK.addListe ner
    >>It seems only one level of namespacing is every necessary for a
    >>library. If that is the case why use an object for this namespacing
    >>than just a prefix? Are there any useful benefits?
    >Probably none, it just looks neater to me to use myNs.foo than
    >MYNS_foo.
    >
    I agree the dot does look a little nicer but...
    I have never had the need to worry about namespacing as I don't use much
    third party software and that is the only time I think it really
    matters. I think the "global namespace pollution" is overplayed a lot.
    Given the choice between FORK_addListene r and FORK.addListene r, I would
    use the dot notation because I am lazy and it is easier to type a . than
    it is to type a _ for me. Fewer fingers to use at once :)


    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

    Comment

    • dhtml

      #3
      Re: Better People

      On Feb 24, 11:51 am, "Richard Cornford" <Rich...@litote s.demon.co.uk>
      wrote:
      dhtml wrote:
      On Feb 23, 10:03 am, Richard Cornford wrote:
      dhtml wrote:
      On Feb 22, 5:31 am, Richard Cornford wrote:
      Peter Michaux wrote:
      [snip]
      I don't want to talk about it much,
      Uh huh.

      and I can think of many better People to
      talk about it with in the event that I did (and some worse, e.g. VK).
      What makes a person better than another? Feel free to base your answer
      on criterion of your choice, e.g. existential, ethical.

      [snip]

      We've got at least three different things in this thread, including
      namespacing, variable declaration, and your project (150k lines js).
      I'll come back to those.

      Garrett
      Richard.

      Comment

      • Richard Cornford

        #4
        Re: Better People

        dhtml wrote:
        On Feb 24, 11:51 am, Richard Cornford wrote:
        <snip - attributions for material not quoted here>
        [snip]
        >I don't want to talk about it much,
        >
        Uh huh.
        >
        and I can think of many better People to
        >talk about it with in the event that I did (and
        >some worse, e.g. VK).
        >
        What makes a person better than another?
        The likely hood that something substantial or conclusive will come out of
        the exchange. Some people can make observations, devise tests and apply
        reasoning, in which interesting truths are revealed, while at the other end
        of the spectrum there a people who will just make a noise to no purpose.
        Feel free to base your answer
        on criterion of your choice, e.g. existential, ethical.
        <snip>

        My criteria are the likelihood that I (or at least somebody) will learn
        something in the process, and the entertainment value that is the return for
        the effort put in.

        Richard.


        Comment

        • dhtml

          #5
          Re: Better People

          On Feb 24, 4:32 pm, "Richard Cornford" <Rich...@litote s.demon.co.uk>
          wrote:
          dhtml wrote:
          On Feb 24, 11:51 am, Richard Cornford wrote:
          >
          <snip - attributions for material not quoted here>
          >
          [snip]
          I don't want to talk about it much,
          >
          Uh huh.
          >
          and I can think of many better People to
          talk about it with in the event that I did (and
          some worse, e.g. VK).
          >
          What makes a person better than another?
          >
          The likely hood that something substantial or conclusive will come out of
          the exchange. Some people can make observations, devise tests and apply
          reasoning, in which interesting truths are revealed, while at the other end
          of the spectrum there a people who will just make a noise to no purpose.
          >
          All positive traits for a javascript-group-poster.

          I did find odd that you chose to mention and even capitalize People.
          The emphasis came through and I think I got it.

          The other one - function decollation. Strange. Decollation means
          'beheading', in case you didn't know. And yeah, that was my mistake -
          I wrapped the 'thing that chopped my head off' in a try-catch. Thanks.

          I want to get back to the other stuff in the thread. I think there's
          more to the global Variable object and properties. I'll need some
          tests, which don't come free - that will take time.

          Regarding strategy and interfaces - I'd like to talk about that too.
          I'd like to see the code technique for critique. I can share how I use
          strategy/adapter, too, but maybe in another thread.

          Garrett
          Richard.

          Comment

          Working...