Why don't Dependencies use Kernel.autoload?

Dependencies implement autoloading as const_missing override.
Sometimes, this creates interesting (to debug) problems. For example:

1. I define module Accounting, in app/models/accounting.rb, which
contains Accounting::Transaction class in
app/models/accounting/transactions.rb
2. I write a spec for Accounting::Transaction, which with "module Accounting".
3. Somewhere in that (or another) spec I call Accounting.foo

Result: if the stars are positioned just so, "module Accounting" may
be already defined by executing the spec for Accounting::Transaction,
therefore app/models/accounting.rb is never loaded. And them I am
staring at some weird error message that talks of Accounting.foo being
not defined (what?! it is defined - I can see that in
app/models/accounting.rb!). Depending on the circumstances, the actual
error can be even more cryptic.

I think, many have gone down this road often enough to feel irritated :slight_smile:

On the other hand, calling Kernel.autoload 'Accounting',
'accounting.rb' would load accounting.rb on first mention of
Accounting, whether as a constant reference or opened by "module
Accounting" statement.

I would like to experiment with calling Kernel.autoload on every .rb
file in Dependencies.load_paths during init (either instead of, or on
top of const_missing override). Has anybody tried that already? Is
there are any reason why this wouldn't work?

I would like to experiment with calling Kernel.autoload on every .rb
file in Dependencies.load_paths during init (either instead of, or on
top of const_missing override). Has anybody tried that already? Is
there are any reason why this wouldn't work?

I'm not aware of anyone trying this out, and also can't find any
references to it in the history of dependencies.rb. But it sounds
like something worth experimenting with.

One challenge with changing the dependency mechanism is that hundreds
of plugins rely on the current behaviour so even a small change can
cause 'huge' breakage in people's applications. Generally the change
required to the plugins is minimal, but that doesn't stop it from
freaking people out.