Project

General

Profile

Actions

Misc #21385

open

Namespace: Suggesting a rename

Added by fxn (Xavier Noria) 6 days ago. Updated 28 minutes ago.

Status:
Open
Assignee:
-
[ruby-core:122343]

Description

I'd like to suggest a rename of namespaces.

The word "namespace" is already taken in Ruby.

We say that classes and modules act as or represent namespaces. Constant paths nest them in practice. We say that it is a best practice that gems create their own namespace, etc.

If the feature goes ahead with this name, the above sentences, well-established in the Ruby community, will start to sound confusing, because that meaning of "namespace" stays.

If you look at the index in Matz's book, "namespaces" is indexed in pages 248–250. Title of section 7.5.1 is "Modules as Namespaces".

Besides, I have had a few experiences explaining the proposal to people, and quickly realizing they assume this is something like C++ namespaces or Java packages. Then, I have to undo that mental model and start all over saying "forget that mental model". Those are like our constant paths, only more simple and strict. I think it may also be confusing in this sense (though this could be OK if it wasn't for the previous point.)

To be constructive: Some alternative names that I have thought about are "isolates", "shields", or "cells". ("sandboxes" is close, but may have security connotations you do not want to suggest.)


Related issues 1 (1 open0 closed)

Related to Ruby - Bug #21341: `Namespace is not a module (TypeError)` without enabling the namespaceOpenActions
Actions #1

Updated by fxn (Xavier Noria) 6 days ago

  • Description updated (diff)

Updated by matheusrich (Matheus Richard) 6 days ago

Another suggestion: Context.

Updated by fxn (Xavier Noria) 6 days ago

More evidence.

The CRuby code base has the predicate rb_namespace_p (I think, since Ruby 2.7):

static inline bool
rb_namespace_p(VALUE obj)
{
    if (RB_SPECIAL_CONST_P(obj)) return false;
    switch (RB_BUILTIN_TYPE(obj)) {
      case T_MODULE: case T_CLASS: return true;
      default: break;
    }
    return false;
}

and now it has a macro with similar name, but different meaning:

#define IS_NAMESPACE(obj) (CLASS_OF(obj) == rb_cNamespace)

Updated by Eregon (Benoit Daloze) 4 days ago

Agreed naming this new feature Namespace is very confusing and misleading.
isolates doesn't sound right because they are not really isolated.
I think Context would be fine.
TruffleRuby has a similar feature called InnerContext (except those have separate heaps and are more like multiple interpreters + easy communication (notably enables passing an object from a context to another), but on a high semantics level it is very similar).

Updated by baweaver (Brandon Weaver) 3 days ago

Some other ideas:

  • Package - Some conflict with Packwerk, but then again would likely be used with it very quickly.
  • Capsule - Similar to Package
  • Realm - Bit Tolkien-esque, but no significant precedence in Ruby of this name being used.
  • Zone - Similar implications as Realm, but a bit less archaic.

Personally fond of Package, as it encapsulates a lot of what we would want out of such a feature, and also aligns with common tool usage that would be likely to leverage such features.

Context can be mixed with RSpec a bit, but probably not a huge issue.

Updated by duerst (Martin Dürst) 3 days ago

I strongly support this proposal. It would avoid a lot of confusion down the line. Ideally, we would use a term that makes it clear that this is something much more wide-reaching, and something that's supposed to be much more rarely used, than your everyday namespace facility that Ruby provides with modules.

Updated by fxn (Xavier Noria) 3 days ago

When I explain the feature a concept that I use naturally is "execution context". Like, "foo.rb runs in its own execution context, and that is set externally, foo.rb is not aware of it."

Actions #8

Updated by hsbt (Hiroshi SHIBATA) 2 days ago

  • Related to Bug #21341: `Namespace is not a module (TypeError)` without enabling the namespace added
Actions #10

Updated by hsbt (Hiroshi SHIBATA) 2 days ago

  • Tags set to namespace

Updated by cheba (Alexander Mankuta) 1 day ago

hsbt (Hiroshi SHIBATA) wrote in #note-9:

FYI: Context is conflict with Mastodon.

I’m fairly confident we can find at least 2 instances of Namespace in the wild.

I don’t think this argument has much weight.

Updated by matz (Yukihiro Matsumoto) about 4 hours ago

Context, Capsule, Realm, and Zone do not seem to represent namespaces, so I don't want to adopt them (although I like those names). I like the name Package too. But I think we should reserve it for high-level APIs.
FYI, I consider this namespace thing as a low level API. And I have a plan to provide higher level API in the future.

Matz.

Updated by matz (Yukihiro Matsumoto) about 4 hours ago

I have to make myself clear. It's fine for me, if we rename Namespace.

Matz.

Updated by fxn (Xavier Noria) about 3 hours ago

Oh, it is interesting to know there's a higher level API in the horizon. Looking forward to see what you have in mind!

With that new context, a "cell" is a low-level thing with inner/independent activity, but it is permeable and can communicate with the exterior. As a metaphor maybe it could match. (Potential name conflicts aside.)

Updated by byroot (Jean Boussier) 28 minutes ago

Regarding the name conflict, if this is meant as a low level API, we could consider something under the newly introduced Ruby module. E.g. Ruby::Context, Ruby::Namespace, etc etc.

This also doesn't prevent deprecating the use of the equivalent top-level constant name for a potential alias in the future if that is desired.

Actions

Also available in: Atom PDF

Like2
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0