Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
another thought on how to implement namespaces
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
rogerdpack  
View profile  
 More options Jun 17 2010, 4:12 pm
From: rogerdpack <rogerpack2...@gmail.com>
Date: Thu, 17 Jun 2010 13:12:45 -0700 (PDT)
Local: Thurs, Jun 17 2010 4:12 pm
Subject: another thought on how to implement namespaces
Here's my latest:

convert this:

using namespace "xyz"
 class String
   def go
   end
 end
end

using namespace "xyz"
 'abc'.go
end

to this:

 class String
   def go_namespace_xyz
   end
 end
end

 'abc'.go_namespace_xyz

How? By remembering 'in namespace xyz, I have previously defined a go
method' and assuming that that's the one they really want.

People would get used to it after awhile.
Thoughts?
-rp


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Oliver Nutter  
View profile  
 More options Jun 17 2010, 7:37 pm
From: Charles Oliver Nutter <head...@headius.com>
Date: Thu, 17 Jun 2010 18:37:24 -0500
Local: Thurs, Jun 17 2010 7:37 pm
Subject: Re: [ruby-optimization] another thought on how to implement namespaces
I actually implemented a hack similar to this in JRuby, whereby you
could specify that all calls within a given scope or file should have
an additional dispatch step that checks for installed namespaces. It
was largely just decorating the call nodes in the AST with additional
logic that only fired when a namespace was active. Not hard to add,
really.

The biggest questions I've had with regards to namespacing are:

* How do you define the scope? Keep in mind that Ruby scopes are only
partially determined at compile time, and constant lookups (for
example) are not resolved until runtime
* How do you know what code should see the namespacing? Should it be
all code downthread from a namespacing call, or should it be only code
local to some Ruby structure (file, module, block)

Groovy is the only language I know of that has attempted to implement
this sort of namespacing, using a "downthread" approach, and I know
it's caused them a lot of problems over time.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roger Pack  
View profile  
 More options Jun 18 2010, 11:13 am
From: Roger Pack <rogerdp...@gmail.com>
Date: Fri, 18 Jun 2010 09:13:47 -0600
Local: Fri, Jun 18 2010 11:13 am
Subject: Re: [ruby-optimization] another thought on how to implement namespaces

> * How do you define the scope? Keep in mind that Ruby scopes are only
> partially determined at compile time, and constant lookups (for
> example) are not resolved until runtime

Hmm. One possibility might be something like Thread.current.scope or what not.

Another possibility that might work cross VM might be to specify known
scopes, like

all_scopes_are :scope1, :scope2, :scope3

Then in each (all) currently existing calsses, alias *all* methods to
their scope equivalents, like

String#each_line => String#each_line_scope1
String#downcase => String#downcase_scope1

Then when you run into a block like

using scope1 do
   ''.downcase
end

You translate it (pre processor?) to

''.downcase_scope1

Might have potential.
-rp


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Caleb Clausen  
View profile  
 More options Jun 18 2010, 11:16 am
From: Caleb Clausen <ca...@inforadical.net>
Date: Fri, 18 Jun 2010 08:16:28 -0700
Local: Fri, Jun 18 2010 11:16 am
Subject: Re: [ruby-optimization] another thought on how to implement namespaces

rogerdpack wrote:
> How? By remembering 'in namespace xyz, I have previously defined a go
> method' and assuming that that's the one they really want.

Ok, I get it. This is a completely static implementation of namespaces.
There would be no dynamic aspect to it at all; not like method or
constant lookup in the least. It's just a scheme for rewriting method
names. I think this could work pretty well, and should have no
performance problems. Tho adding yet another scheme for name lookup
disturbs me... the method and constant lookup rules are hard enough to
keep track of already.

> Groovy is the only language I know of that has attempted to implement
> this sort of namespacing, using a "downthread" approach, and I know
> it's caused them a lot of problems over time.

Yeah, no, that's a real bad idea, I can see. You don't want arbitrary
code that you call to be affected by the namespace of the caller.

All the attempts to add namespaces to ruby so far ahve had performance
problems. And tho I think a sufficiently sophisticated implementation
could implement namespaces with no performance drawbacks, it just hasn't
happened yet.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Caleb Clausen  
View profile  
 More options Jun 18 2010, 11:20 am
From: Caleb Clausen <ca...@inforadical.net>
Date: Fri, 18 Jun 2010 08:20:16 -0700
Local: Fri, Jun 18 2010 11:20 am
Subject: Re: [ruby-optimization] another thought on how to implement namespaces

rogerdpack wrote:
> Here's my latest:
> How? By remembering 'in namespace xyz, I have previously defined a go
> method' and assuming that that's the one they really want.

Let me expand on what (I see) Roger's idea is:

namespace Foo
  class Bar
    def baz
    end
  end
end

namespace Foo
  Bar.new.baz #gets rewritten to Bar.new.bar_namespace_Foo
  Bar.new.quux #does not get rewritten; no method quux in namespace Foo
end


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roger Pack  
View profile  
 More options Jun 18 2010, 12:46 pm
From: Roger Pack <rogerdp...@gmail.com>
Date: Fri, 18 Jun 2010 10:46:40 -0600
Local: Fri, Jun 18 2010 12:46 pm
Subject: Re: [ruby-optimization] another thought on how to implement namespaces

> namespace Foo
>  Bar.new.baz #gets rewritten to Bar.new.bar_namespace_Foo
>  Bar.new.quux #does not get rewritten; no method quux previously defined in namespace Foo
> end

Yeah that's right, for that style.  except it would be
baz_namespace_Foo I suppose.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Oliver Nutter  
View profile  
 More options Jun 30 2010, 6:10 pm
From: Charles Oliver Nutter <head...@headius.com>
Date: Wed, 30 Jun 2010 17:10:29 -0500
Local: Wed, Jun 30 2010 6:10 pm
Subject: Re: [ruby-optimization] another thought on how to implement namespaces

On Fri, Jun 18, 2010 at 11:46 AM, Roger Pack <rogerdp...@gmail.com> wrote:
>> namespace Foo
>>  Bar.new.baz #gets rewritten to Bar.new.bar_namespace_Foo
>>  Bar.new.quux #does not get rewritten; no method quux previously defined in namespace Foo
>> end

> Yeah that's right, for that style.  except it would be
> baz_namespace_Foo I suppose.

The important thing to remember here is that Ruby has very little
static syntax right now, so this would be somewhat unique.

Class definitions in Ruby are not really static class definitions;
they're just opening (and possibly instantiating) a Class object and
running code against it. Same goes for Modules and constants defined
anywhere; they can't be sorted out statically ahead-of-time (the best
you can do is guess based on standard patterns).

In JRuby we've had to deal with this to support compiling Ruby into
Java classes. Specifically, we have started to support translating the
"apparent" static structure of a Ruby class into the equivalent Java
class structure, without actually running the code. It's tweaky,
though, and it's easy to walk off the edge of what we can support
statically.

The namespacing stuff you're talking about would definitely be nice to
have statically supported, but statically propagating it across files
leads right back into the same problems...since Ruby files know
nothing of each other until runtime.

It's a hard problem, and part of the reason I haven't said more about
it or tried to implement more prototypes is because I haven't found a
solution that doesn't have a lot of ugly warts. I suspect Matz is in
the same boat...

- Charlie


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »