Issue #14795 has been updated by tonytonyjan (Wei-Hang Jian).


jeremyevans0 (Jeremy Evans) wrote:
> tonytonyjan (Wei-Hang Jian) wrote:
> > IMHO, I would suggest use `Kernel::autoload`, thus we don't need to type `net/http/status` when we want it, and they will never be loaded into memory until we try to access the constant `STATUS_CODES`. Isn't it win-win?
> 
> No, it's a trade-off, and a bad trade-off in my opinion.  See #5653.  Even if the particular implementation issues with autoload are or have been addressed, my main problem with autoload is that libraries that use it are a pain to use in security sensitive code that uses Dir.chroot.  Well designed libraries should require all files at load/application startup time, and avoid requiring files during application runtime, and autoload is a hidden runtime require.

Hi Jeremy, thank you for the reference, I didn't know that thread before (It seems like there has not been a conclusion yet :(
 
By the way, I can see that `cgi.rb` is still using `autoload` so I am not quite sure if `autoload` is really deprecated for stdlib.



----------------------------------------
Bug #14795: Should  'net/http' require 'net/http/status' ?
https://bugs.ruby-lang.org/issues/14795#change-72330

* Author: sakuro (Sakuro OZAWA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
net/http/status.rb has been added (#12935) but it is [not required from net/http.rb](https://github.com/ruby/ruby/blob/0342fcbd51f2f423541f862c8d8e35873d849963/lib/net/http.rb#L1629-L1642) while other net/http/*.rb files are already required.
Is this intentional?

```
$ irb
>> require 'net/http'
=> true
>> Net::HTTP::STATUS_CODES
:
NameError (uninitialized constant Net::HTTP::STATUS_CODES)
>> require 'net/http/status'
=> true
>> Net::HTTP::STATUS_CODES
=> {100=>"Continue", ..., 511=>"Network Authentication Required"}
```




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>