Re: Namespaces

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

On Sun, 06 Jun 2004 07:54:44 -0700, irv mullins
<guest at RapidEuphoria.com> wrote:

>Why is this? Logically, there should now be two functions visible to 
>my main program (test.exu), one named two:foo()
>and another function named just foo().

I'm sure this isn't the shortest answer you'll get, but:

You have two functions named foo(), one of which can be qualified
using the namespace "two". There is nothing actually named
"two:foo()", eg if you include misc.e as something, you can still call
reverse(), you don't have to call "something:reverse()" [unless of
course reverse() is defined somewhere else]. Clearly that can save
alot of editing when there is only one conflict over a single name,
not everything in the included file(s).

Suppose you have a source, say customers.e, which contains add(),
delete(), and update() routines, and you write some code which calls
them and test it.

You also create a file orders.e which contains the same named
routines, but obviously they affect a different file or something, and
again you write some code which calls them and test it.

(It might make a bit more sense to think of third party routines or an
application written by more than one programmer).

Now you add them both to your main application, and of course you get
a 'namespace qualifier required' on the first add() call (say). So you
fix it, probably sensibly performing a global search for add(), and
run the program again. If it worked the way you suggest, the program
will compile cleanly, but, whichever way you went, half of the
delete() and update() calls would be to the wrong one, and there would
be no further error or warning messages to help you.

If the interpreter assumed no namespace means the first include (ie
the one with no "as" clause), then after one warning, you would have
to perform a global search on every global in the source you added a
namespace qualifier to, plus any further code you add will not give an
error if you forget to specify the namespace when you should have.

Does that make sense?

Regards,
Pete

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

Search



Quick Links

User menu

Not signed in.

Misc Menu