mode where "autoload" behaves like an immediate "require"
How about a feature to switch "autoload" behavior to "require" immediately.
autoload is a feature for lazy loading.
matz dislikes autoload as [Feature #5653].
I heard that he dislikes class (and other) definitions at arbitrary timing.
I agree that eager loading is safer than lazy loading.
However, lazy loading realize shorter loading time and
it makes development cycle shorter.
It is more important for larger applications as Eregon said in
It is especially important when library loading causes I/O (code generation from DB schema).
These two, safety of eager loading and easier development of lazy loading, conflicts.
But if we can distinguish production mode and development mode,
we can enjoy both benefits.
So, I propose a feature to select autoload behavior from two modes:
- autoload behaves as lazy loading as now in development mode
- autoload behaves as eager loading (immediately invokes "require") in production mode.
There are several idea to switch the mode:
- $AUTOLOAD_MODE = :eager or :lazy
- RubyVM.autoload_mode = :eager or :lazy
- ObjectSpace.autoload_mode = :eager or lazy
I'm not sure there is a good enough one in above list, though.