ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: fxn@hashref.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:91228] [Ruby trunk Feature#5653] "I strongly discourage the use of autoload in any standard libraries" (Re: autoload will be dead)
Date: Wed, 23 Jan 2019 13:39:35 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-76475.20190123133933.a65c2241692efca5@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-5653.20111121172400@ruby-lang.org

Issue #5653 has been updated by fxn (Xavier Noria).


Hey! I am the author of Zeitwerk, let me do a quick followup here.

First and foremost, I'd like to be very straightforward saying that if Kernel#autoload is killed tomorrow, that would be fine with me. I'd shutdown Zeitwerk and Rails 6 plans without regrets. The Ruby core team are the stedwards of the language. You know better than anybody else the rationale for your decisions, and if you believe you have to definitely say goodbye to Kernel#autoload I'd profoundly respect it.

Having say that. Why have I worked on Zeitwerk while being well aware of this 7-years old issue? For several reasons: The first one is that being so old means to me this issue is not black/white and perhaps is still open for consideration. Another one is that I wanted to solve some very specific problems for which I don't know another solution today. And a third one is that the existence of something like Zeitwerk, Rails adoption, and the kind of problems that it solves could bring more information or context when pondering the future of Kernel#autoload.

Zeitwerk is motivated specifically by two problems: One problem is Rails autoloading, which cannot reproduce Ruby semantics due to lack of information in const_missing, whereas Kernel#autoload logic is builtin in the interpreter and works perfectly. The other one is brittle requires in non-trivial projects. Both of them are explained in the post and Zeitwerk README.

1) Being able to reload code is handy in web applications development. That is replacing the objects stored in the autoloaded constants, not reopening classes by reevaluating the files.

2) In any non-trivial project, getting the require calls right is difficult, you always forget some and gives load order bugs.

3) If you structure your project in a conventional manner in which file paths match constant paths, the requires don't feel DRY. You are repeating something all the time that could be automated.

4) Being able to work as if all your classes and modules are just available everywhere (as in Rails) is a great user experience. That includes what I call explicit namespaces in which you can use child constants in the body of the parent class or module, something that wouln't even be possible eager loading.

5) Being able to transparently load code on demand in development speeds things up in large code bases.

Now, we have to differentiate the problem from the solution. The points are the problem, the use cases, and a solution based on Kernel#autoload a solution that is possible today. If there were other ways to solve the same problems, that would be also great.

And, finally, let me say it again: Whatever decision the Ruby core team agrees on, I'd respectfully accept without regrets.

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

* 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/

  parent reply	other threads:[~2019-01-23 13:39 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-5653.20111121172400@ruby-lang.org>
2011-11-21  8:28 ` [ruby-core:41171] [ruby-trunk - Feature #5653] "I strongly discourage the use of autoload in any standard libraries" (Re: autoload will be dead) Hiroshi Nakamura
2011-11-21 19:51   ` [ruby-core:41179] " Aaron Patterson
2011-11-22  5:03     ` [ruby-core:41192] " Eric Hodel
2011-11-22  0:57 ` [ruby-core:41183] " jonathan rochkind
2011-11-22  1:25   ` [ruby-core:41184] " Yukihiro Matsumoto
2011-12-01  1:16 ` [ruby-core:41421] " Stephen Touset
2011-12-01  1:34 ` [ruby-core:41423] " Stephen Touset
2011-12-01  1:36 ` [ruby-core:41426] " Yehuda Katz
2011-12-01 14:14 ` [ruby-core:41432] " Stephen Touset
2012-03-27 15:33 ` [ruby-core:43755] [ruby-trunk - Feature #5653][Assigned] " mame (Yusuke Endoh)
2012-06-14 17:37 ` [ruby-core:45653] [ruby-trunk - Feature #5653] " trans (Thomas Sawyer)
2012-06-30 15:24 ` [ruby-core:45991] " nahi (Hiroshi Nakamura)
2012-06-30 16:35 ` [ruby-core:46000] " rosenfeld (Rodrigo Rosenfeld Rosas)
2012-06-30 22:23 ` [ruby-core:46023] " nahi (Hiroshi Nakamura)
2012-07-01 13:10 ` [ruby-core:46052] " rosenfeld (Rodrigo Rosenfeld Rosas)
2012-07-01 18:13 ` [ruby-core:46079] " mame (Yusuke Endoh)
2012-07-01 18:32 ` [ruby-core:46084] " trans (Thomas Sawyer)
2012-07-01 18:56 ` [ruby-core:46086] " funny_falcon (Yura Sokolov)
2012-07-03 13:53 ` [ruby-core:46142] " rosenfeld (Rodrigo Rosenfeld Rosas)
2012-11-23 23:36 ` [ruby-core:49910] " mame (Yusuke Endoh)
2013-02-12 13:38 ` [ruby-core:52154] " rosenfeld (Rodrigo Rosenfeld Rosas)
2013-02-17  6:17 ` [ruby-core:52353] " ko1 (Koichi Sasada)
2013-05-22  3:46 ` [ruby-core:55107] " reset (Jamie Winsor)
2013-06-24  8:49 ` [ruby-core:55629] " se8 (Sébastien Durand)
2013-08-31  9:17 ` [ruby-core:56929] " boris_stitnicky (Boris Stitnicky)
2014-01-30  6:16 ` [ruby-core:60263] " shibata.hiroshi
2015-04-07 12:40 ` [ruby-core:68780] [Ruby trunk " plribeiro3000
2019-01-21 17:57 ` [ruby-core:91213] [Ruby trunk Feature#5653] " rafaelmfranca
2019-01-23 10:19 ` [ruby-core:91224] " shyouhei
2019-01-23 10:55 ` [ruby-core:91227] " eregontp
2019-01-23 13:39 ` fxn [this message]
2019-01-24 10:19 ` [ruby-core:91247] " fxn
2019-01-28 16:22 ` [ruby-core:91307] " rr.rosas
2019-01-28 18:38 ` [ruby-core:91309] " rafaelmfranca
2019-02-03 23:01 ` [ruby-core:91388] " Greg.mpls
2019-02-05 14:27 ` [ruby-core:91411] " rr.rosas
2019-02-07  6:20 ` [ruby-core:91450] " matz
2019-02-07  7:02 ` [ruby-core:91455] " akr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-76475.20190123133933.a65c2241692efca5@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).