Re: Namespaces

new topic     » goto parent     » topic index » view thread      » older message » newer message

Howdy!

>Could you please explain namespaces?   Why are they important/good/possibly 
>bad?  Who uses them and why, etc?
>
>Start at ground zero, as the only namespaces I deal with are on Netware 
>volumes, and are certainly unrelated to what you're referring to :).
>
>Thanks,
>Ted

Okay.  Here's a situation in which you need namespaces.  Suppose Bob wrote an
include file named
foo.ew, which has a global function named getValue().

Now suppose John wrote an include file named bar.ew, which also has a global
function named
getValue().

And now, suppose Mr. Fines wrote a Euphoria app like this:

include foo.ew
include bar.ew

atom
	theValue

theValue = getValue()

Now then, which getValue() does the interpreter use?  The one in foo.ew, or
bar.ew?  That's an
itchy situation, and is caused by the fact that Euphoria uses one, global
namespace.  As you may
realize, this causes a hairy situation in which the author of an include file
has to hope to hell
they don't use the same name for a routine as the authors of *all the other
include files* that a
developer might wish to include.

The answer to this is to give one or more include files a separate namespace. 
Many languages do
this.  Here's a modified version of the example with a type of namespacing
scheme that has been
suggested here on the list:

include foo.ew
include bar.ew

atom
	theValue

theValue = foo.getValue()

This tells the interpreter to use foo.ew's getValue, and thus clears up the
ambiguity.  In other
words, it tells the interpreter to use the getValue() in the foo namespace.  If
you wanted to
drop the "foo", you could tell the interpreter to assume that you're talking
about the foo
namespace:

using foo.ew
    theValue = foo.getValue()
end using

Hope I didn't confuse you more,

Travis

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu