Re: Namespaces

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

The reason I was asking about namespaces is because I think a lot of people
are looking to namespaces as a way to implement OOP in Py. I don't think
that it's that good of a fit, either in Py, or in Euphoria.

Although namespaces *could* be implemented in an OOP sort of way, that would
be inconsistant with the rest of Euphoria. My guess (and that's all it is,
an uninformed guess) is that Robert's implementation of namespace will
simply be a way to make local (non-global) objects in a file visible. At
least, this approach seems sensible to me. For example:

   -- foo.e
   integer i

   -- bar.ex
   import foo.e as stuff -- 'i' is visible as 'stuff.i'

All the namespace prefix does is make local objects visible to the importer.
Because globals have the 'side effect' of being visible to anyone after they
are declared, I don't even think they properly belong in the namespace:

   -- foo.e
   global integer.i

   -- bar.ex
   import foo.e as stuff -- 'i' is global, NOT 'stuff.i'

Finally, I suspect that the 'modules are loaded once' rule is going to
continue:

   -- foo.e
   integer i

   -- bar.ex
   import foo.e as stuff -- 'i' is visible as 'stuff.i'
   import foo.e as nonsense -- 'i' is visible as 'nonsense.i'

the file 'foo.e' file will be loaded a single time, and made visible through
the 'stuff' and 'nonsense' namespaces under 'bar.ex'. But 'stuff.i' and
'nonsense.i' both refer to the same variable.

This is all speculation, but I think that trying to turn namespaces into
objects goes against the Euphoria way of doing things.

The problem with trying to turn namespaces into OO is that they are
statically bound. Now, I *know* that there are tons of languages out there
that implement namespaces dynamically (such as Python). But I don't think
that Robert is likely to take that direction, and I'm not sure that's the
right approach for Py, either.

What I *do* think would work well would be the addition of associative
arrays. Here's three examples from JavaScript, which basically do the same
thing:

   myCar.make = "Ford"
   myCar.model = "Mustang"
   myCar.year = 1969

   myCar["make"] = "Ford"
   myCar["model"] = "Mustang"
   myCar["year"] = 1969

   myCar = {make:"Ford", model:"Mustang", year:1969}

Anyway, that's my two bits...

Thanks!

-- David Cuny

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

Search



Quick Links

User menu

Not signed in.

Misc Menu