41 points · by blasdel · 17y ago · 52 comments
http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-pr...
Giles Bowkett has also written about the related issue of screwing up the load path:
http://gilesbowkett.blogspot.com/2009/04/unshiftfiledirnamef...
It's also worth noting that Ruby 1.9 requires rubygems automatically, as it's included in the standard library.
Bundler: http://github.com/wycats/bundler
Rip: http://hellorip.com/
Please don't put #include <stdlib.h> in your C source files. By doing this you remove my ability to compile your files in an environment where the standard library is not present. Instead, whenever you need to compile a file that uses stdlib.h functionality, simply use a small wrapper file that includes stdlib.h and then includes your source file, and compile that.
* Configuring /bin/sh to point to my shell of choice is trivial (and common)
* Overriding the shebang is even more trivial, if I don't like sh, I can call `./mysupershell foobar`
Meanwhile, if I don't want gems on my machine and manage my $LOAD_PATH manually or through other means (which seems to be Ryan's case) but you decided that your library was going to require rubygems dammit, I have the choices between
* Installing rubygems (and duplicating my $LOAD_PATH handling efforts) anyway because you decided I was to have rubygems on my machine whether or not I liked it
* Adding an empty rubygems.rb to my $LOAD_PATH (yeah, kludge)
* Hacking Kernel#require to ignore gems request (yeah, horrible hack)
Most every machine I've been on has both /bin/sh and /usr/bin/env, so it's a bit of a non-issue: but does anyone know what the 'correct' shebang for a sh script is?
In fact that's a good example, though it's in python: if you use `#!/usr/bin/python` as your shebang your script will break under virtualenv, whereas if you use `#!/usr/bin/env python` it will work perfectly.
Now /bin/sh is probably a POSIX requirement so it'll always be there and you can always override the shebang with an explicit shell call (or by temporarily rebinding /bin/sh though that one requires root access), but going through env doesn't cost you (as a programmer) more and it simplifies the job of the users (if they need to sandbox your script in some way)
Unfortunately on Ubuntu (and probably other Linux variants) you can’t pass arguments to the interpreter, e.g. the following gives an error on Ubuntu (works on OpenSolaris, FreeBSD, and OS X):
#!/usr/bin/env ruby -wKU
puts "æblegrød"Are you serious?
What Ryan's gripping against here is that the people requiring rubygems usually don't care for rubygems itself. They just want to require a library which (on their machine) happens to be managed via rubygems.
And this management is not the sole strategy. Somebody else could be using another utility, or even no utility at all if they handle their $LOAD_PATH manually (which Ryan apparently does).
And in these cases, requiring rubygems breaks their platform: they might not want or care for rubygems. In any case, it's usually not needed so why require it?
And that's Ryan's point: by requiring rubygems when it's not needed (which is most of the time) in your library, you're forcing people to use rubygems whether they like (or need) it or not.
Furthremore, his analogy is also wrong because even with a /bin/sh shebang *it's trivial for me to overload it by calling `./mysupershell yourscript`. With `require rubygems` there's no such recourse (apart from `require` hackery or other such crap).
When you feel the urge to strike "require 'rubygems'" because some shit isn’t working, stop and consider whether one of these solutions is more appropriate:
1) An empty rubygems.rb in your $LOAD_PATH should do the trick.
2) Redefine Kernel#require to intercept calls to load rubygems and silently discard them.
Why You Shouldn't Force Non-Rubygems On People
When I write you a library, appplication, or tests, I may not want to have to care how you execute my program. When you require that I not include 'rubygems' in my code, you remove my ability to make that decision. I cannot anticipate all of your requirements in advance, but you can set up your environment properly such that the defaults I choose are overridden.
Ruby 1.9 actually ignores "require 'rubygems'" entirely which I suppose will make this whole issue moot, as soon as we all start using it.. um, any day now.
So if I write a ruby program that needs rubygems I need to ask people that will run it to please run my program with "ruby -rubygems foo.rb" or set an environment variable, instead of just requiring the gems. Because that would infringe on the domain system administrator of that system. That doesn't make much sense to me.
I think Ryan's point is that most of the time your program doesn't require rubygems itself. You just happen to manage your libraries using gems, somebody else could do it an other way (and never need rubygems), but you're forcing that person to install gems regardless.
gem 'png', '= 1.1'
The good part about rubygems is that it's possible to get a certain version of a gem. I'd rather use gem and version than just require "png", and get god knows what version or file.
Stuff like this: http://github.com/mojombo/jekyll/blob/2f2e45bedf67dedb8d1dc0... or that: http://github.com/mwunsch/weary/blob/cd7b35ccee66757c5efb0a0... is probably the kind of stuff Ryan rages against in his rant (though you'd have to ask him if that's that, and how he'd see you use case)
"I think Ryan's point is that most of the time your program doesn't require rubygems itself."
Yeah! You could have manually downloaded the files for all the libraries you need, placed them in the directory, and required them directly. See, who needs rubygems? Oh hang on, rubygems is about 1000x easier than doing all that.
"You just happen to manage your libraries using gems"
Yes, because gems are the standard way of managing libraries in Ruby, and work transparently and conveniently. Where the hell is Ryan getting all these gem-using libraries anyway, if not from gems? And what is supposed to be wrong with it, anyway? I have never had a problem using a non-gem library even with gems present and a duplicate installed. Just require the non-gem lib first. What is so freaking hard? I assume it's some stupid problem he has to solve at Heroku - and his solution is trying to change how the entire Ruby community does things, to their detriment, benefiting only him. Screw him.
Oh well, anyway .. who cares. You're a crank and so is he. Rubygems is here to stay and if you don't like it .. well again, who cares.
Yes, why not?
> placed them in the directory
Placed them in any directory on my $LOAD_PATH, yes indeed.
> and required them directly
Uh no, there's nothing to touch there. Library is on $LOAD_PATH, any require $the_library will find it perfectly normally.
> See, who needs rubygems?
Nobody. Rubygems is a very nice convenience, not a requirement for anything.
> Where the hell is Ryan getting all these gem-using libraries anyway, if not from gems?
Tarballs? Github? Rubyforge? His colleagues? The Internet?
And as a side note: if the library was obtained from gems, then it was loaded from gems, which means by the time the library is reached rubygems has already been required and loaded.
Where's the sense in requiring the tool which loaded you in the first place, exactly? Doesn't that seem a bit dumb to you?
> And what is supposed to be wrong with it, anyway?
And what's wrong with not wanting to use it, anyway? (and what's wrong with it is that they clutter the $LOAD_PATH. You don't care, Ryan apparently does)
> Oh well, anyway .. who cares. You're a crank and so is he. Rubygems is here to stay and if you don't like it .. well again, who cares.
You… completely missed the point. It's impressive.
"Why You Shouldn’t Force Rubygems On People:
When I use your library, deploy your app, or run your tests I may not want to use rubygems."
If someone's writing a library or app.. it's up to THEM whether they want to require rubygems or not. If you don't like how they do it.. then don't use their application/library, it's simple.
Most people create code for their OWN use and THEN publish it for others to use.
But… why? Most of the time it's not like they actually need gems. They just happen to use gems as a $LOAD_PATH manager, so they're leaking their environment configuration into the library. How can anyone defend that?
It's like hardcoding the paths of dynamic libraries, or respawning your shell scripts because damn it if any god damn user is going to run it with anything other than /bin/bash.
It's completely insane.
Oh come on. That's like saying "you should not make your MacOSX app require Finder just because some people just happen to use it as their file manager". Just happen? It's the default, and overwhelmingly dominant, choice! It's freaking bundled in 1.9 core!
rtomayko is a prominent and well regarded community member but he's pretty much a crank on this issue. He is the extreme odd one out who doesn't like rubygems, so it's on him to deal with it, rather than causing inconvenience for everyone else. He doesn't even give a good, or any, reason why he doesn't use gems. And as if I'm going to write -rubygems every time I run anything, give me a break.
Rubygems is the official package manager and is used without any issue by 99.9% of Rubyists. It's not 100% perfect but in general works beautifully and greatly contributes to making everything in Ruby "just work". There is no reason for people to stop using it as the default choice.
So is Rails core member Yehuda Katz.
So is Rails core member Josh Peek.
So is Rails core member Jeremy Kemper.
Calling Ryan "the extreme odd one out" is a) untrue and b) unfair.
Yeah it is. And indeed you shouldn't.
> Just happen? It's the default, and overwhelmingly dominant, choice! It's freaking bundled in 1.9 core!
So fucking what? (and as others have said, in 1.9 rubygems is required by default so that's a very good reason not to require it yourself ever).
> Rubygems is the official package manager and is used without any issue by 99.9% of Rubyists.
And so the rest should just take it up the ass and live with completely insane and nonsensical decisions such as randomly requiring rubygems just because?
> There is no reason for people to stop using it as the default choice.
That is not what Ryan says. Ryan doesn't care how you handle your own $LOAD_PATH. If you want to use gems, knock yourself out, that's your own business not his. Ryan just asks that you don't force others to use rubygems without any justification.
The author is a smart guy. Major contributor to Sinatra, developer at Heroku, etc.
You might be right about the rubygems issue, but the random bile and personal attacks make it hard to take you seriously.