Package and Namespace

Hi list.

I’ve found an article on Ruby which criticizes Ruby’s lack of
package & namespace support. (Sorry I forgot the URL)

As you know, every modern language has namespace facility.
Even XML does have one to avoid name conflicts. Contrarily,
Ruby does not have explicit namespace facility. Though module
can provide with namespace facility it is not mandatory and
is not being used even in standard library.

So, I’d like to ask two questions:

  1. Don’t you think Ruby need a package/namespace concepts?

  2. How would you solve the following problem:

[Start of a.rb]

I want to declare class Struct because I love that name so much.

The name Struct perfectly describes my domain problem as well.

class Struct
end

Foo = Struct.new :bar # I’d like to use Struct in standard library.
[end of a.rb]

Sincerely,
Minkoo S.

On Thursday 01 June 2006 3:52 pm, Minkoo S. wrote:

As you know, every modern language has namespace facility.
Even XML does have one to avoid name conflicts. Contrarily,
Ruby does not have explicit namespace facility. Though module
can provide with namespace facility it is not mandatory and
is not being used even in standard library.

So, I’d like to ask two questions:

  1. Don’t you think Ruby need a package/namespace concepts?

It does, though, as you yourself point out. The fact that it isn’t
mandatory
isn’t a problem.

  1. How would you solve the following problem:

[Start of a.rb]

I want to declare class Struct because I love that name so much.

The name Struct perfectly describes my domain problem as well.

class Struct
end

Foo = Struct.new :bar # I’d like to use Struct in standard library.
[end of a.rb]

Simple. If you want to use Struct out of the standard library, then you
have
to put your Struct in a different space.

module MyStuff
class Struct
# Struct stuff be found here…
end
end

my_struct = MyStuff::Struct.new

Kirk H.

On 6/1/06, Minkoo S. [email protected] wrote:

Hi list.

Hi you,

I’ve found an article on Ruby which criticizes Ruby’s lack of
package & namespace support. (Sorry I forgot the URL)

Ruby supports namespaces via Modules. Modules do many thing more than
namespaces but I don’t see any exception to use them as pure
namespaces too.

[…]

Cheers,

Thank you Kirk.

Actually, the second question was my effort to think of some nice
example which mandates namespace concept in Ruby.

But, you actually solved my contrived example. And I’m wondering
if there is any real problem that needs namespace.

Sincerely,
Minkoo S.

On Jun 1, 2006, at 23:08, Minkoo S. wrote:

Okay, here’s another example.

I have Point class provided by XYZ company.
I also have Point class provided by ABC company.

Now, I have to creates an instance of XYZ.Point from an
instance of ABC.Point. How can I solve this problem?
I have to mention ABC.Point and XYZ.Point in the same file.

abc_point = ABC::Point.new
xyz_point = XYZ::Point.new

Or am I missing something?

matthew smillie.

Okay, here’s another example.

I have Point class provided by XYZ company.
I also have Point class provided by ABC company.

Now, I have to creates an instance of XYZ.Point from an
instance of ABC.Point. How can I solve this problem?
I have to mention ABC.Point and XYZ.Point in the same file.

Sincerely,
Minkoo S.

On Thursday 01 June 2006 4:04 pm, Minkoo S. wrote:

Thank you Kirk.

Actually, the second question was my effort to think of some nice
example which mandates namespace concept in Ruby.

But, you actually solved my contrived example. And I’m wondering
if there is any real problem that needs namespace.

Sure. When I work on my web framework, I am pretty carefule to keep the
whole
thing within the ::Iowa namespace. I do this so that I avoid unexpected
conflicts/interactions with other code.

For instance, there are several useful extensions to String that I
wanted to
use, but I didn’t want to risk a bad interaction between those
extensions and
other code. So, there’s Iowa::String available for when I need those
extensions. The various cache implementations, TMail wrapper, utility
methods, constants, and other generally useful code is all inside of the
Iowa
namespace. In an application running within the framework, the
framework
takes pains to load application code into separate namespaces, as well.
All
of this makes sure that if someone writes or downloads a piece of code
to use
in an application, that it won’t butt heads with the Iowa code and cause
difficult to resolve problems.

Ruby’s namespaces, perhaps, are not perfect, but they are simple and
pretty
good and work well when trying to keep my code from stepping on your
code.
It’s always been a bit of a puzzle to me why, historically, there hasn’t
been
more extensive use of them in libraries that people release. That
single
thing was the strangest single thing that I found when I came to Ruby
from
the Perl world.

Kirk H.

On Jun 1, 2006, at 6:20 PM, Matthew S. wrote:

I have to mention ABC.Point and XYZ.Point in the same file.

abc_point = ABC::Point.new
xyz_point = XYZ::Point.new

I think the OR was suggesting that company ABC and company XYZ
neglected to wrap their classes in a containing module/namespace so
you have two top level classes named Point. I think at that point
you suggested politely to both ABC and XYZ that they should
distribute their code within a module.

You still have the problems of two authors picking the same top level
module name.

Gary W.

From: [email protected] [mailto:[email protected]]
Sent: Friday, June 02, 2006 1:53 AM

Now, I have to creates an instance of XYZ.Point from an
distribute their code within a module.

You still have the problems of two authors picking the same top level
module name.

There were a discussion somewhere in ruby-talk about the syntax like:
module ABC
end

ABC::load(‘abc-point’) #here we have all code from abc-point.rb inside
module ABC

Or something like this.

Moreover, there is already brilliant Script[1] library, which allows to
do
such kind of things right now.

V.

  1. Script

On 6/2/06, Minkoo S. [email protected] wrote:

And I am curious why namespace capability is not part of
Ruby language. Is there any standardized solution for
handling two ‘Point’ classes from two different company?

Yes. Yell at them for not using namespaces in their own code.

I’ll admit that I’ve not always used namespaces cleanly, and at times
I’ve also ended up “claiming” rather large swaths of namespace
(PDF::Writer anyone?), but I am very consistent about documenting
that behaviour and namespacing within that.

-austin

Thank you for the pointer and explanation.

Does anybody know exact conclusion of the discussion
on ABC::load(‘abc-point’) syntax?

My memory is blurred, and if I remember correctly,
the suggestion was rejected because ABC::load syntax
does not anything but

require ‘abc-point’

module ABC
include abc-point
end

and such an implementation is already there and trivial.

And I am curious why namespace capability is not part of
Ruby language. Is there any standardized solution for
handling two ‘Point’ classes from two different company?

Sincerely,
Minkoo S.

On Jun 2, 2006, at 6:26 AM, Minkoo S. wrote:

Sincerely,

On Jun 1, 2006, at 23:08, Minkoo S. wrote:
abc_point = ABC::Point.new
xyz_point = XYZ::Point.new

I think the OR was suggesting that company ABC and company XYZ
neglected to wrap their classes in a containing module/namespace so
you have two top level classes named Point. I think at that point
you suggested politely to both ABC and XYZ that they should
distribute their code within a module.

I’m confused. In what language would these two companies putting
their code outside of a namespace declaration not be a problem
then? As far as I can tell ruby provides as much namespace support as
any other language, and no language (AFAIK)has a way to make two top-
level Point classes work the right way if they aren’t inside
different namespaces.

I’m confused. In what language would these two companies putting
their code outside of a namespace declaration not be a problem
then? As far as I can tell ruby provides as much namespace support as
any other language,

You could do it in a language with “selector namespaces”, I think. I
believe it’s been a feature discussed for Ruby 2.0, but I don’t know
what its status is.

-mental

On Jun 2, 2006, at 4:08 PM, MenTaLguY wrote:

I thought selector namespaces were going to be for methods? Anyway, I
still don’t see the “problem” with modules as namespaces. Asking how
to solve the problem of people putting objects in the same namespace
with the same identifier seems akin to trying to “solve” the problem
of how to stop x / 0 from being an error.

Logan C. wrote:

does not anything but
Ruby language. Is there any standardized solution for

On Jun 1, 2006, at 6:20 PM, Matthew S. wrote:

instance of ABC.Point. How can I solve this problem?

I’m confused. In what language would these two companies putting their
code outside of a namespace declaration not be a problem then? As far
as I can tell ruby provides as much namespace support as any other
language, and no language (AFAIK)has a way to make two top-level Point
classes work the right way if they aren’t inside different namespaces.
Does it matter? There’s potentially a way to solve it in Ruby that
doesn’t involve changing the offending code. What other languages do is
hardly relevant. In a way, Ruby provides much better namespace support
than other languages, because it’s actually feasible to change the
namespace of code after the fact.