Ecere SDK/eC Forums • View topic - namespace




Ecere SDK/eC Forums

Ecere Developers Community

namespace

General help with the eC language.

namespace

Postby redj » Wed Feb 09, 2011 11:24 am

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

-redj
redj
 
Posts: 107
Joined: Sun Jan 17, 2010 10:03 am

Re: namespace

Postby jerome » Wed Feb 09, 2011 1:40 pm

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 578 times
test.ec
(682 Bytes) Downloaded 557 times
nameSpaces.ec
(917 Bytes) Downloaded 566 times
jerome
Site Admin
 
Posts: 623
Joined: Sat Jan 16, 2010 11:16 pm


Return to eC Language

Who is online

Users browsing this forum: No registered users and 4 guests

cron