From: Robert Klemme Date: 2009-10-14T23:38:14+09:00 Subject: Re: Hey you! Stop using relative requires! 2009/10/14 Intransition : > I recently came across two different programs that had this line in a > bin/ executable: > >  $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../ > lib")) > > This stuff makes me sad. The use of RubyGems is masking some bad > practices here. The above code would not work with a traditional site > installation. I am not sure I understand why this is an issue. If it is in an executable I write locally then I know where libraries reside (of course, I would set RUBYLIB appropriately but for special tests or so this might be necessary nevertheless). If it is an executable which is part of a distribution, paths might be as well known. The only situation which could be problematic is an executable which is deployed on arbitrary systems without modification. Hm... > I imagine this sort of thing has probably trickled down form Rails, > where programmers are accustom to deploying apps rather than releasing > them. > > So here are the general rules (that I can think of off the top of my > head): > > * Don't mess with the $LOAD_PATH. PERIOD. > * Use relative lookup only when you must, eg. using bundled HTML > templates. > * Any relative paths you do use must remain within the confines of > their main directory (eg. lib/) > * Don't use a relative lookup for any ,rb or .so/.dll loading. PERIOD. > * Oh, and it should never need to necessary to require 'rubygems'. > > These rules do not apply to building, eg. your Rakefile, running tests > and such. But try to follow them as much as possible anyway. As far as I can see we would need at least two different sets of rules 1. requiring in library files 2. requiring in "main" files (executables) Maybe more. Kind regards robert PS: Why the changed name? Are you moving? -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/