Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Avoid Collisions, Desire Co-existence

Avoid Collisions, Desire Co-existence

2023 TokyuRubyKaigi 14 Lightening Talk about NameSpaces in Ruby and its motivations.
#tqrk14

Satoshi Tagomori

July 31, 2023
Tweet

More Decks by Satoshi Tagomori

Other Decks in Technology

Transcript

  1. Satoshi Tagomori, a.k.a. tagomoris TokyuRubyձٞ14 - Jul 29, 2023 Avoid

    Collisions, Desire Co-existence Names, Modules, Versions, and NameSpaces
  2. Satoshi Tagomori (@tagomoris) Independent developer Technical Consultant OSS Maintainer •

    Fluentd • MessagePack / msgpack-ruby • Norikra, Woothee, … tagomoris
  3. Collisions Names, Modules, Versions Name Collisions: No one can use

    a name in two ways. Module Collisions: Modules can be modified, globally, from anywhere. Version Collisions: Two different versions of a module can’t be loaded.
  4. Name Collisions In Fact: App vs Gem, App vs App,

    Gem vs Gem • RoR app classes vs Gem library module names • RoR app classes vs RoR app classes • “Con fi guration”
  5. Module Collisions Module global con fi guration changes module Tagomoris

    (@black_magic:false) User App code Dependency library .method_call {result}
  6. Module Collisions Module global con fi guration changes module Tagomoris

    (@black_magic:true) User App code Dependency library .enable_black_magic!
  7. Module Collisions Module global con fi guration changes module Tagomoris

    (@black_magic:true) User App code Dependency library .method_call {result}
  8. Version Collisions Tagomoris v2 vs v1 User App code module

    Joker1007 VERSION: 3.1.4 module Tagomoris VERSION: 1.y.z
  9. Version Collisions Tagomoris v2 vs v1 module Tagomoris VERSION: 2.0.x

    User App code module Joker1007 VERSION: 3.1.4 module Tagomoris VERSION: 1.y.z 😱
  10. NameSpaces in languages Many ways, Many hells… • JavaScript/TypeScript (npm)

    • Copy everything, import one-by-one “in past” (download/copy cost …) • Install once, symbolic links, import one-by-one • Java (classes w/ FQDN) • Write once, install once, import locally (name collisions, dependency hell) • Class loaders (oops….) • Python (pip) • Install once, import one-by-one (dependency hell) • Go • Install once, import locally (name collisions)
  11. NameSpace Requirements What is it? • One native extension libraries

    of two versions at a time Ruby Process LibraryX version: a.b.c “x.so” LibraryX version: x.y.z “x.so”
  12. No, Still on the Way Native Extensions, Top-level References, Open

    classes, and… • Calling C-functions of di ff erent gem • Top-level references • Enforcing use of ‘::NAME’ to access top-level names • Silent failures of open class accesses • Automatic namespace adoptions • Accessing modules in namespaces without any source code updates • To be implemented in PoC
  13. Next Step More Concerns, More Features, and Agreements • https://bugs.ruby-lang.org/issues/19744

    • “[WIP] Namespace on Read PoC” https://github.com/tagomoris/ruby/pull/1 • and
 
 দߐRubyձٞ10
 https://matsue.rubyist.net/matrk10/