Namespace and modules

P

Phil Tomson

Hi

Using modules to define namespace is good and efficient?

Sure.

Commentary: It's interesting that we're getting all these questions about
namespaces and modules lately.

Phil
 
R

Robert Klemme

Phil Tomson said:
Sure.

Commentary: It's interesting that we're getting all these questions about
namespaces and modules lately.

Maybe there is a major migration of C++ developers towards Ruby going on. I
can image why that would be... :))

robert
 
K

Kevin Bullock

Using modules to define namespace is good and efficient?

It seems to be effective. Semantically, though, there is a bit of
weirdness in this idiomatic usage of modules.

Modules define:
1. namespaces, within which symbols are referenced
2. mix-ins, which add behavior to another module or class

These two distinct uses cause some "semantic shear," to paraphrase Neal
Stephenson.

Taking a different view, though, these two uses can be seen as the same
thing. Modules are more than namespaces, and are thereby more flexible
while still solving the same problems as namespaces. Thus it may not be
Ruby that needs to change (to add explicit namespaces), but our
perspective of it.

I haven't fully thought through the module v. namespace distinction,
but these are my current thoughts. Discuss :)

Pacem in terris / Mir / Shanti / Salaam / Heiwa
Kevin R. Bullock
 
T

T. Onoma

Modules define:
1. namespaces, within which symbols are referenced
2. mix-ins, which add behavior to another module or class

Looking at this I think there are three uses:

1. namespaces, for grouping functionality
2. mix-ins, which add behavior to another module or class
3. service, like namespace but for accessing class-level methods and data

Classes themselves can be used for purposes 1 & 3.
These two distinct uses cause some "semantic shear," to paraphrase Neal
Stephenson.

Taking a different view, though, these two uses can be seen as the same
thing. Modules are more than namespaces, and are thereby more flexible
while still solving the same problems as namespaces. Thus it may not be
Ruby that needs to change (to add explicit namespaces), but our
perspective of it.

Perhaps, though I tend to think separation might make for better code. It
seems strange when a class is defined within a class. It has no functional
significance. Its just something you can do if you'd like.

Barring this, I'd rather go in the other direction and have module and class
be the same thing.
I haven't fully thought through the module v. namespace distinction,
but these are my current thoughts. Discuss :)

Better late than never :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top