2 ms·
I just read that post again. Good post, but it's talking about something different. This HN article is about Ryan's views on the matter. Of course I agree that
by sho 17y ago
I just read that post again. Good post, but it's talking about something different. This HN article is about Ryan's views on the matter.
Of course I agree that libraries should not require it. I often want to use libraries by themselves. But apps!? What do you suggest - manually place each gem directory, by its full system file path, into $LOAD_PATH? How on earth are you going to use a gem installed in its default location by the ubiquitous "gem install" method, if not by, at some point, requiring rubygems?
This whole kerfuffle was started by this gist: http://gist.github.com/54177 http://gist.github.com/54177. Note the title: Why "require 'rubygems'" In Your Library/App/Tests Is Wrong. I thought that was a ridiculous thing to say then and still do. In my app!? That no-one else will ever see, my personal little IRC bot or something? What, pray tell, is the difference between loading rubygems on the command line every single time you run the program, or just writing in the source because you know your app needs it?
I have no quarrel with best practise for responsible use of gems. I agree completely with what Josh Peek writes. People publishing gems to public repos should absolutely learn how to do it without stepping on anyone's shoes. But that is not what Ryan says. Ryan says this:
You should never do this in a source file included
with your library, app, or tests:
require 'rubygems'
and that is extremist and indefensible and, IMO, flat out wrong.
update: I mean, let's have an example. Let's take a top-level app that depends on things. I know, thin.
Here we are: http://github.com/macournoyer/thin/blob/9f391ed7fcc7c202a32e520bda9323be25d666e4/lib/thin.rb http://github.com/macournoyer/thin/blob/9f391ed7fcc7c202a32e...
He needs eventmachine. He requires rubygems and loads it. Tell me what he is doing wrong. Tell me how he should do it differently. Because I can not see what is wrong with that. And if that usage is wrong, then what is the point of even having Rubygems.
update 2: And I would like to clarify that I agree Rails should only be requiring Rubygems when it is being used at the top level, such as being launched from the binary or from the script directory, not when it is being loaded as a lib. It is always the top level app's responsibility to set up paths, etc - rails is a special case because it's both an app and a library.
- masklinn 17y ago> He needs eventmachine. He requires rubygems and loads it. Tell me what he is doing wrong. He requires rubygems even though what he wants is eventmachine. What's the sense? > Tell me how he should do it differently. Don't require rubygems. Rubygems isn't used anywhere in the code, why require it? > And if that usage is wrong, then what is the point of even having Rubygems. Managing your own $LOAD_PATH on your own machine(s). That's the point of rubygems in the first place.
- sho 17y agoOh for fuck's sake. So what do you suggest? Bundle eventmachine with thin? "He requires rubygems even though what he wants is eventmachine. What's the sense?" Do you know even know what rubygems is? It is used to require other libraries. Like eventmachine. That is a textbook usage. I was regretting insulting you before, but after hearing that, I don't anymore - you're an idiot. Hey defunkt, do you endorse masklinn's comment above too?