From: Cezary Date: 2011-06-10T23:03:20+09:00 Subject: [ruby-core:36935] Re: [Ruby 1.9 - Feature #4824] Provide method Kernel#executed? On Fri, Jun 10, 2011 at 07:20:32AM +0900, Rocky Bernstein wrote: > > Issue #4824 has been updated by Rocky Bernstein. > > > Cezary Baginski wrote: > > This may seem like heresy, but isn't really: > > > > __FILE__ == $0 > > > > just a hack for letting a file be *both* a script and a "library" > > at the same time? With the only sane use (I can think of) being > > adding unit tests? > > I wrote my thoughts regarding this to ruby-core on June 5-6. See > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/36772. Yes, I read your comments (I read the list). It was what got me thinking. I didn't like checking using file path strings either. > It has one answer to your question which, in sum, is "demo code". > Demonstration code is not the same as a unit test. Yes, but shouldn't that be in a README or example.rb instead? > But there is another use. One can write a program that has a > command-line interface, but folks can use this as a library instead. > For example see, https://github.com/rocky/ps-watcher Shouldn't there be an executable script installed in bin/ loading a lib/ps-watcher/cli.rb file ? It would be accessible from $PATH. And unit/integration tests can be simpler and more robust. I understand the use case(s), but I don't see why '__FILE__ == $0' is really that useful and good practice enough to be explicitly supported by the language. As for the name - anything containing 'main' assumes familiarity with C-type languages, which may or may not be the case for novices. -- Cezary Baginski