On Fri, 4 May 2001, Marko Schulz wrote:

> On Fri, May 04, 2001 at 08:51:32AM +0900, David Alan Black wrote:
> > On Fri, 4 May 2001, Conrad Schneiker wrote:
> >
> > > # On Thu, 3 May 2001, Wayne Scott wrote:
> > > #
> > > # >     #simplified for this discussion
> > > # >     def fetch(arg2)
> >
> > [snip]
> >
> > > # >                  @cache.dup.each do |arg2, file|       ## (1)
> >
> > [snip]
> >
> > > # I don't know if the behavior should change but I think it should at
> > > # least issue a warning if there is reuse like this.
> > >
> > > I think this is an important suggestion.
> > >
> > > Answers such as:
> > >
> > >   1) I should have known better.
> > >   2) You should have known better.
> > >   3) Here is a way around this.
> > >   4) There is (or soon will be) a better feature to use.
> > >   5) Once you know Ruby better, this won't be a problem for you.
> > >
> > > are all true to some degree, but are somewhat beside the point of accident
> > > prevention in the cases that people are caught unawares.
> >
> > I certainly agree that this should not be warned about under -w.
>
> I certainly do not agree with you. This should be warned about under -w.

I think of -w things as things one should never do -- that is, I like
all code to run clean under -w.  I have to admit that I don't think
I've ever assigned to an existing variable with the |var| syntax.  But
I'm not ready to say that there is no possible reason ever to do so.

I know we (communally) have been around the block (ha ha) on this.
And I'm a little constrained in defending it, since Matz has said he
wants to change it :-)  Still, what I don't get is: *if* one accepts
that in "n = 0 ; ary.each do |n| ... end" one is doing a series of
assignments to (existing) n, then why is it any more likely that one
would *accidentally* reuse the name 'n' in such a case than in this
case:

  def thing
    n = 100
    n = []    # whoops, should have used x, forgot I had an n
  end

Should I get a warning there on that second assignment? I think we'd
agree that in this case, the programmer is expected to take
responsibility.  It seems to me, then, that in the block case, the
confusion/mistake is only an issue if one does *not* accept that the
syntax means what it means.  In other words, it is an assignment in
current scope, so we should do what we usually do with assignments in
current scope.

I know that block syntax comes with certain connotations which "x = y"
syntax doesn't have, and I know I'm arguing this rigidly.  And I admit
it's partly because I'm still hoping that |var| won't give way to
<var>, which I really don't like the appearance of.  But it's only
partly that :-)


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav