Forum: Ruby Package and Namespace

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
47b36de21d7ecbc824c81d24802a6290?d=identicon&s=25 Minkoo Seo (pool007)
on 2006-06-01 23:54
(Received via mailing list)
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 Seo
1b5341b64f7ce0244366eae17f06c801?d=identicon&s=25 Kirk Haines (Guest)
on 2006-06-02 00:00
(Received via mailing list)
On Thursday 01 June 2006 3:52 pm, Minkoo Seo 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.

> 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]

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 Haines
3da82a61d5fbd74242cc6f671a5a32e4?d=identicon&s=25 Nicolas Desprès (Guest)
on 2006-06-02 00:04
(Received via mailing list)
On 6/1/06, Minkoo Seo <minkoo.seo@gmail.com> 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,
47b36de21d7ecbc824c81d24802a6290?d=identicon&s=25 Minkoo Seo (pool007)
on 2006-06-02 00:07
(Received via mailing list)
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 Seo
47b36de21d7ecbc824c81d24802a6290?d=identicon&s=25 Minkoo Seo (pool007)
on 2006-06-02 00:10
(Received via mailing list)
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 Seo
31af45939fec7e3c4ed8a798c0bd9b1a?d=identicon&s=25 Matthew Smillie (Guest)
on 2006-06-02 00:22
(Received via mailing list)
On Jun 1, 2006, at 23:08, Minkoo Seo 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.
1b5341b64f7ce0244366eae17f06c801?d=identicon&s=25 Kirk Haines (Guest)
on 2006-06-02 00:41
(Received via mailing list)
On Thursday 01 June 2006 4:04 pm, Minkoo Seo 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 Haines
E7559e558ececa67c40f452483b9ac8c?d=identicon&s=25 unknown (Guest)
on 2006-06-02 00:53
(Received via mailing list)
On Jun 1, 2006, at 6:20 PM, Matthew Smillie 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 Wright
2c7c807a1df0c76a8fc823c709b501a9?d=identicon&s=25 Victor Shepelev (Guest)
on 2006-06-02 01:09
(Received via mailing list)
From: gwtmp01@mac.com [mailto:gwtmp01@mac.com]
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. http://redshift.sourceforge.net/script/doc/index.html
47b36de21d7ecbc824c81d24802a6290?d=identicon&s=25 Minkoo Seo (pool007)
on 2006-06-02 12:27
(Received via mailing list)
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 Seo
31ab75f7ddda241830659630746cdd3a?d=identicon&s=25 Austin Ziegler (Guest)
on 2006-06-02 20:10
(Received via mailing list)
On 6/2/06, Minkoo Seo <minkoo.seo@gmail.com> 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
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-06-02 20:26
(Received via mailing list)
On Jun 2, 2006, at 6:26 AM, Minkoo Seo wrote:

>
> Sincerely,
>> > > On Jun 1, 2006, at 23:08, Minkoo Seo 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.
912c61d9da47754de7039f4271334a9f?d=identicon&s=25 MenTaLguY (Guest)
on 2006-06-02 22:10
(Received via mailing list)
> 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
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-06-02 22:54
(Received via mailing list)
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.
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-06-03 10:38
(Received via mailing list)
Logan Capaldo wrote:
>> does not anything but
>> Ruby language. Is there any standardized solution for
>>> > On Jun 1, 2006, at 6:20 PM, Matthew Smillie 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.
This topic is locked and can not be replied to.