From: fxn@... Date: 2019-01-24T10:19:40+00:00 Subject: [ruby-core:91247] [Ruby trunk Feature#5653] "I strongly discourage the use of autoload in any standard libraries" (Re: autoload will be dead) Issue #5653 has been updated by fxn (Xavier Noria). Let me add a couple of things. In case const_missing is discussed, these are the reasons why implementing autoloading based on const_missing doesn't fly (from memory): 1) The nesting is unknown. 2) Whether the missing constant was relative is unknown. 3) Since const_missing is the last resort in the constant resolution algorithms, you may miss an autoload if some class/module up in the nesting or the ancestor chain happens to have a constant with the same name. 4) It is not thread-safe. On the other hand, Zeitwerk is based on these techniques (some are not portable as of this writing, but would hope they are in the future for compatibility with CRuby): 1) Kernel#autoload, related API, and the fact that it is thread-safe. 2) Constants API. 3) Kernel#autoload calls Kernel#require (Zeitwerk decorates it). 4) TracePoint for the :class event if there is at least one explicit namespace (hotel.rb & hotel/pricing.rb), to support the very common edge case in which Hotel includes Hotel::Pricing and you need to set an autoload on Hotel for :Pricing before that line is reached. (I am aware of https://bugs.ruby-lang.org/issues/14104 and this week I have made some changes in that line, as in https://github.com/fxn/zeitwerk/commit/a1bd83b10521f41f7f74e921602839a1813d11e4). Additionally, Zeitwerk by design uses internally absolute paths only, there are no lookups in $LOAD_PATH or autoload paths, gems using Zeitwerk should load a tad faster. Even more, a code base managed by Zeitwerk does not even need to be in $LOAD_PATH. Any other information that you'd like to know please just tell me! ---------------------------------------- Feature #5653: "I strongly discourage the use of autoload in any standard libraries" (Re: autoload will be dead) https://bugs.ruby-lang.org/issues/5653#change-76493 * Author: matz (Yukihiro Matsumoto) * Status: Assigned * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: Next Major ---------------------------------------- Hi, Today, I talked with NaHi about enhancing const_missing to enable autoload-like feature with nested modules. But autoload itself has fundamental flaw under multi-thread environment. I should have remove autoload when I added threads to the language (threads came a few months after autoload). So I hereby declare the future deprecation of autoload. Ruby will keep autoload for a while, since 2.0 should keep compatibility to 1.9. But you don't expect it will survive further future, e.g. 3.0. I strongly discourage the use of autoload in any standard libraries. matz. ---Files-------------------------------- noname (500 Bytes) 5653.pdf (38.3 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: