473,497 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

pseudo-namespacing in JavaScript

[from <URL: http://groups.google.com/group/comp.lang.javascript/msg/825bb682f5f456a5>]

On Feb 18, 11:02 pm, David Mark <dmark.cins...@gmail.comwrote:
On Feb 19, 1:14 am, Peter Michaux <petermich...@gmail.comwrote:
Actually I think that FORK_addListener 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
"FORKINGLEAVETHISALONE" would be a less likely candidate for an
overwrite.
I've been thinking about this more for a library API.

prefix namespacing

FORK_addListener

vs.

object namespacing

FORK.addListener

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_addListener is faster than accessing FORK.addListener.
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
Feb 22 '08 #1
4 1340
Peter Michaux said the following on 2/22/2008 2:38 AM:
On Feb 21, 10:34 pm, RobG <rg...@iinet.net.auwrote:
>On Feb 22, 3:27 pm, Peter Michaux <petermich...@gmail.comwrote:

[snip]
>>prefix namespacing
FORK_addListener
vs.
object namespacing
FORK.addListener
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_addListener and FORK.addListener, 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.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 22 '08 #2
On Feb 24, 11:51 am, "Richard Cornford" <Rich...@litotes.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.
Feb 24 '08 #3
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.
Feb 25 '08 #4
On Feb 24, 4:32 pm, "Richard Cornford" <Rich...@litotes.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.
Feb 25 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2811
by: Andrew Thompson | last post by:
I would like to create a menu that uses the 'active' pseudo-class to highlight the current page, but I cannot get it to work. The URL http://www.lensescapes.com/tst/nav/1.jsp shows the attempts...
4
4487
by: Stephen Poley | last post by:
The issue of the focus pseudo-class came up a few weeks ago, and I finally got around to trying it out (better late than never ...) The recommended order given for the pseudo-classes is link,...
1
3299
by: Steven T. Hatton | last post by:
ISO/IEC 14882:2003: "5.2.4 Pseudo destructor call The use of a pseudo-destructor-name after a dot . or arrow -> operator represents the destructor for the non-class...
1
1730
by: rudderstick | last post by:
Hi there all, I have an interesting problem.... I work for a company that develops software for the building industry and would like to distribute one of our software products via the web. ...
70
6168
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like...
0
1106
by: Kevin Frey | last post by:
WebControl contains properties such as ControlStyle and Style for controlling the style of a web-control. In particular the Style property is a CssStyleCollection that simply comprises key-value...
3
2486
by: shakthi | last post by:
Hi all. Am a beginner in device driver programming. Please tell me how to get handle for a pseudo driver..., a driver with no device connected i suppose.Am using CreateFile() win32 API. Since it is...
2
2425
by: Martin Leese | last post by:
Hi, I am having trouble with CSS in that I can't get the pseudo-element 'first-line' to work. I have some pages that contain dialog. I use a <dlfor this, with the character's name in a...
4
3269
by: k3pp0 | last post by:
Hey. I've got a very basic newbie question, I hope you can understand me. Sorry for asking it, first of all. I see a lot of sites (e.g. communities) with a url-structure like this:...
3
4752
by: bytehunter | last post by:
Hello, I hope this is the best place to ask my question. I was wondering if there was such a thing as a pseudo terminal in Windows. For those unfamiliar, in Linux/Unix one can create a pseudo...
0
7120
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.