Replacement for __FILE__ == $0 
Author Message
 Replacement for __FILE__ == $0


Quote:
> OK, this will probably end up being an RCR, but first I
> want to get some
> feedback. Does this construct bother anybody else?:

>    if __FILE__ == $0
>            ... Do stuff ...
>    end

The __FILE__ part doesn't bother me, but the $0 does. How
about just creating an alias for $0? It's the main file,
right? so __MAINFILE__ or $MAIN_FILE or something like that
seems reasonable. I think *ALL* the cryptic perl leftovers
should have friendly aliases, and most already do.

I don't really like the idea of creating a wrapper for the
entire expression.

Kevin

__________________________________________________
Do You Yahoo!?
Get email alerts & NEW {*filter*} video instant messaging with Yahoo! Messenger. http://www.*-*-*.com/



Wed, 10 Mar 2004 07:43:05 GMT  
 Replacement for __FILE__ == $0

Quote:

> > OK, this will probably end up being an RCR, but first I
> > want to get some
> > feedback. Does this construct bother anybody else?:

> > if __FILE__ == $0
> > ... Do stuff ...
> > end

> The __FILE__ part doesn't bother me, but the $0 does. How
> about just creating an alias for $0? It's the main file,
> right? so __MAINFILE__ or $MAIN_FILE or something like that
> seems reasonable. I think *ALL* the cryptic perl leftovers
> should have friendly aliases, and most already do.

Doesn't "require 'English'" do what you want?

require 'English'

if __FILE__ == $PROGRAM_NAME
    ... Do stuff....
end



Wed, 10 Mar 2004 08:29:39 GMT  
 Replacement for __FILE__ == $0

Quote:


> > OK, this will probably end up being an RCR, but first I
> > want to get some
> > feedback. Does this construct bother anybody else?:

> >       if __FILE__ == $0
> >               ... Do stuff ...
> >       end

> The __FILE__ part doesn't bother me, but the $0 does. How
> about just creating an alias for $0? It's the main file,
> right? so __MAINFILE__ or $MAIN_FILE or something like that
> seems reasonable. I think *ALL* the cryptic perl leftovers
> should have friendly aliases, and most already do.

> I don't really like the idea of creating a wrapper for the
> entire expression.

Why? It means one less thing that has to be remembered (two less things
if you require 'English'). Instead of having to remember

        if __FILE__ = $0        # or $PROGRAM_NAME

you have just have to remember

        in_main_file { stuff }

It's prettier, too, and more explanatory (although I'll admit, I'm still
not sure about the name).

Nathaniel

<:((><
+ - -
| RoleModel Software, Inc.
| EQUIP VI



Wed, 10 Mar 2004 08:41:25 GMT  
 Replacement for __FILE__ == $0

Quote:
> Why? It means one less thing that has to be remembered
> (two less things
> if you require 'English'). Instead of having to remember

>    if __FILE__ = $0        # or $PROGRAM_NAME

> you have just have to remember

>    in_main_file { stuff }

I am always reluctant to add new keywords or methods to
core classes. Using require 'English' (which I wasn't aware
of) is reasonable in this case, although I would argue that
$0 is nearly useless as-is, and so should be aliased.
Having a perl background shouldn't be a prerequisite for
using Ruby.

Adding in_main_file increases the total complexity of Ruby,
which is already a bit more complex than I would like. Just
my own preference.

Kevin

__________________________________________________
Do You Yahoo!?
Get email alerts & NEW {*filter*} video instant messaging with Yahoo! Messenger. http://www.*-*-*.com/



Wed, 10 Mar 2004 09:05:46 GMT  
 Replacement for __FILE__ == $0
Nathaniel Talbott:

Quote:
> OK, this will probably end up being an RCR, but first I want to get
> some feedback. Does this construct bother anybody else?:

>    if __FILE__ == $0
>            ... Do stuff ...
>    end

Yes, it does.

Kevin Smith:

Quote:
> I am always reluctant to add new keywords or methods to
> core classes.

Me too.

Quote:
> Adding in_main_file increases the total complexity of Ruby,
> which is already a bit more complex than I would like. Just
> my own preference.

Agreed.

But this should not be an excuse to not provide means for writing
code that's simpler to read. We could try to build a library as a first
step, something like (naming to be discussed)

require 'mainfile'
in_main_file { ... }

Those who are bothered by the current implementation (as I am)
could use the library, the others don't have to.

Pit



Wed, 10 Mar 2004 14:04:08 GMT  
 Replacement for __FILE__ == $0

Quote:
> ...
> I am always reluctant to add new keywords or methods to
> core classes. Using require 'English' (which I wasn't aware
> of) is reasonable in this case, although I would argue that
> $0 is nearly useless as-is, and so should be aliased.
> Having a perl background shouldn't be a prerequisite for
> using Ruby.
>...
> Kevin

..

The $0 notation isn't strictly Perl.  I first encountered it when
being introduced to the first edition of the Macintosh MPW.  They
had taken it in from Unix, but I don't think that Perl was around
then.  I think that they got it from grep (regular expressions).  
And that was just a small twist from C's command argument
addressing, where the command arguments were stored in a 0 based
array, with the name of the command being the first argument (i.e.,
arg[0]).
--
 Charles Hixson

 Copy software legally, the GNU way!
 Use GNU software, and legally make and share copies of software.
 See:
    http://www.gnu.org
    http://www.redhat.com
    http://www.linux-mandrake.com
    http://www.calderasystems.com
    http://www.linuxapps.com



Thu, 11 Mar 2004 01:43:52 GMT  
 Replacement for __FILE__ == $0

Quote:


> > ...
> > I am always reluctant to add new keywords or methods to
> > core classes. Using require 'English' (which I wasn't aware
> > of) is reasonable in this case, although I would argue that
> > $0 is nearly useless as-is, and so should be aliased.
> > Having a perl background shouldn't be a prerequisite for
> > using Ruby.
> >...
> > Kevin
> ...

> The $0 notation isn't strictly Perl.  I first encountered it when
> being introduced to the first edition of the Macintosh MPW.  They
> had taken it in from Unix, but I don't think that Perl was around
> then.  I think that they got it from grep (regular expressions).  
> And that was just a small twist from C's command argument
> addressing, where the command arguments were stored in a 0 based
> array, with the name of the command being the first argument (i.e.,
> arg[0]).
> --
>  Charles Hixson

$0 has been around in Unix almost forever, and was even in PC-DOS from
the beginning for .bat files.

Mike

--
Michael P. Sullivan                                  
Distributed Computing Systems, LLC                         Cell: 516-429-2080

    * UNIX Systems and Database Consulting, Architecture and Management *
"Failing to plan, is planning to fail... plan for the worst, hope for the best"



Thu, 11 Mar 2004 01:57:23 GMT  
 Replacement for __FILE__ == $0

Quote:
> $0 has been around in Unix almost forever, and was even
> in PC-DOS from the beginning for .bat files.

True. However, that doesn't make it any more friendly or
useful for someone who has never seen it. Most of Ruby is
perfect as a "first language", and I would love to see the
remaining "icky bits" made friendly as well.

However, it's not a personal crusade of mine right now.
Just a background wish.

Kevin

__________________________________________________
Do You Yahoo!?
Get email alerts & NEW {*filter*} video instant messaging with Yahoo! Messenger. http://www.*-*-*.com/



Thu, 11 Mar 2004 02:26:20 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. $0 == __FILE__ idiom for Unix only?

2. __FILE__ == $0 refactored in Ruby?

3. Appending to $0 or $_

4. variable as search-pattern: if ($0 ~ myVar)

5. executable awk scripts and shell var $(basename $0)

6. Newbie Help required: Deleting double entries in a line ($0)

7. !x[$0]++

8. mechanism of application ($0 or the line)

9. $0 == false ??

10. program name -> perl's $0

11. ruby 1.6.5, irb $0

12. Maximum size of $0

 

 
Powered by phpBB® Forum Software