Comment on this RCR (edit wiki page) | RCRchive home

RCR 220: Automatic completion of Namespace

submitted by rolo on Tue Feb 24 2004 05:24:57 AM -0800

Status: superseded


Abstract

There is a need to oraganize libraries with depths more 1. This tree can become quite deep. (depth > 3). To always write a fully qualified name is laborious task.

Problem

Example:

require 'Mycompany/Net/Pop'
headers = Mycompany::Net::Pop::Command.top()

It is easier to use just

require 'Mycompany/Net/Pop'
headers = Command.top()

Proposal

Allow ruby require statement to resolve namespaces.

Analysis

No Idea. Can Anybody help!

I think that's literally impossible. If you require two features that both have Command classes, there's no possibility of resolution.

I would recommend:

require 'Mycompany/Net/Pop'
include Mycompany::Net::Pop

Then Command will be part of the current namespace.

-- David Black


I think that's literally impossible. If you require two features that both have Command classes, there's no possibility of resolution.

Not Really. Conflicts can be handled by using fully qualified name. Anyway how can using include help this.

-- rolo [Rohit Lodha]


Consider this:

require 'A/B/C'
require 'D/E/C'
What is C.new at this point? And does it change, depending on the order? Or depending on whether you rewrite the code and remove something?

As for include... what it does is eliminate the need to use the fully-qualified path. That was your goal, wasn't it? :-)

-- David Black


Add comments here



Vote for this RCR

Strongly opposed [3]
Opposed [1]
Neutral [0]
In favor [0]
Strongly advocate [0]

Change the status of this RCR to:

accepted

rejected

withdrawn


I think that's literally impossible. If you require two features that both have Command classes, there's no possibility of resolution.

I would recommend:

require 'Mycompany/Net/Pop'
include Mycompany::Net::Pop

Then Command will be part of the current namespace.

-- David Black


I think that's literally impossible. If you require two features that both have Command classes, there's no possibility of resolution.

Not Really. Conflicts can be handled by using fully qualified name. Anyway how can using include help this.

-- rolo [Rohit Lodha]


Consider this:

require 'A/B/C'
require 'D/E/C'
What is C.new at this point? And does it change, depending on the order? Or depending on whether you rewrite the code and remove something?

As for include... what it does is eliminate the need to use the fully-qualified path. That was your goal, wasn't it? :-)

-- David Black


It's also possible to do this with simple assignment, since modules are simply objects.

require 'Mycompany/Net/Pop'
cmd = Mycompany::Net::Pop::Commands
headers = cmd.top

This way, you can even have David's example:

require 'A/B/C'
require 'D/E/C'
abc = A::B::C dec = D::E::C

-austin


Back to RCRchive.


RCR Submission page and RCRchive powered by Ruby, Apache, RuWiki (modified), and RubLog