Why Using require ‘rubygems’ Is Wrong

Tháng Một 31, 2009

Source: http://www.rubyinside.com/why-using-require-rubygems-is-wrong-1478.html

Ryan Tomayko, currently known as one of the lead developers of Sinatra, was definitely not mincing his words yesterday when he posted Why “require ‘rubygems'” In Your Library/App/Tests Is Wrong:

You should never do this in a source file included with your library, app, or tests:

require ‘rubygems’

The system I use to manage my $LOAD_PATH is not your library/app/tests concern. Whether rubygems is used or not is an environment issue. Your library or app should have no say in the matter. Explicitly requiring rubygems is either not necessary or misguided.

But.. why?

When I use your library, deploy your app, or run your tests I may not want to use rubygems. When you “require ‘rubygems'” in your code, you remove my ability to make that decision. I cannot unrequire rubygems, but you can not require it in the first place.

I hadn’t thought of it this way before, but Ryan makes a lot of sense. The choice of library management system should be down to the environment and not enforced by a library or a single portion of a larger application.

Check out Ryan’s post for the deeper rationale and see what you think. He’s definitely got me thinking twice about using require ‘rubygems’ in my own scripts, although as the slow migration over to Ruby 1.9 begins, perhaps it will become a non-issue, since RubyGems is included with Ruby 1.9 and loaded by default. Thoughts?


Trả lời

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Đăng xuất / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Đăng xuất / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Đăng xuất / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Đăng xuất / Thay đổi )

Connecting to %s

%d bloggers like this: