namespace

General help with the eC language.
Post Reply
redj
Posts: 105
Joined: Sun Jan 17, 2010 10:03 am

namespace

Post by redj »

Question from JF:
How do namespace work in Ecere? I see them declared, but not used in the imports or code.

-redj
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: namespace

Post by jerome »

Dear JF,

First off, I'd like to point out that namespace support is partial at the moment.

Namespaces are primarily there to organize classes and functions by topic (e.g. gfx, gui...), especially in the API Reference.

They ARE also there (at least in theory) to work around name collisions, whereas you can explicitly refer to a class or function in a specific namespace, e.g. ecere::gfx::Surface .

You can define a 'default namespace' for the project, as is done in ecere.epj (ecere) in the project settings, which will be added at the head of all namespaces defined within the project source files.

You can also define a namespace in a source file, e.g. namespace gfx; or namespace gui::drivers;

Now, I profoundly dislike C++ code where you have to do a whole bunch of using blablabla;
So by default, eC will search through all known namespaces to resolve identifiers. The idea (i don't think that's working right now) is that if there are more than one identifiers resolving, it should give you at least a warning and tell you which one it chose by default (Then you could explicitly refer to the object you meant).

However there are still some things clashing when there are name collisions across multiple namespaces. Limited testing was done and I put the namespace development on hold to work on other things. I'm attaching my latest nameSpaces test project. We're also probably missing NameSpace tickets on Mantis, I don't remember where the work left to be done is.

Another compiler option is available called 'strict namespaces', which will not look through every namespace. However, I think we're still missing the 'using' keyword which would be useful for that purpose (Otherwise you'd have to explicitly refer to every single object in a namespace).

(See also the Tao page 98-99)
Attachments
nameSpaces.epj
(1.1 KiB) Downloaded 919 times
test.ec
(682 Bytes) Downloaded 896 times
nameSpaces.ec
(917 Bytes) Downloaded 922 times
Post Reply