Re: Namespace

new topic     » goto parent     » topic index » view thread      » older message » newer message
SPringle said...

Namespaces also gives you data encapsulation.

I'm afraid not. It doesn't work that way at all. It only disambiguates symbol names and has no effect at all on data storage.

SPringle said...

A Euphoria program could start like this:

include sets_simple.e as person_set 
include sets_simple.e as inventory_set 
include sets_binary.e as receipt_set 

If you always use the namespaces, you can shift from one implementation to another simply by changing the included filenames named in the file. This works as long as the identifiers are present in all of the implementations and implement the same thing.

In the situation above, only a single copy of the variables declared in sets_simple.e would have RAM reserved for them. Meaning that even though one can include a file many times, only the first time actually reserves space for its contents. Subsequent includes for the same file (with different namespace IDs) just create aliases for the exposed symbols without reserving further space.

For example, if the file simple_sets.e had the symbol global integer status defined then the following code was executed ...

person_set:status = 1 
inventory_set:status = 2 
writefln("Status: Person = [], Inventory = []", {person_set:status, inventory_set:status}) 

The output would be ...

Status: Person = 2, Inventory = 2 

Because there is only one status field created in RAM but it has two names now.

It is expected that some release after V4.1 will implement something along the lines that you have mentioned.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu