We have 'use strict' and 'my', and now 'our', but no 'use local-scope' - why? 
Author Message
 We have 'use strict' and 'my', and now 'our', but no 'use local-scope' - why?



Quote:
>I've long been baffled that there is no pragma to automatically declare
>all variables as default locally-scoped.  

Because nobody knows what that would mean.

Quote:
>This way, rather than typing 'my' everywhere, one could just type the
>ocassional 'our' and assume everything else is local (er, my'd).

But local to what?  The file? The innermost block in which it appears?
Neither of those are sensible.

Quote:
>Thoughts?

I think you haven't thought this through carefully enough.

rd
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print



Sat, 27 Sep 2003 12:02:23 GMT  
 We have 'use strict' and 'my', and now 'our', but no 'use local-scope' - why?

Quote:



> >I've long been baffled that there is no pragma to automatically declare
> >all variables as default locally-scoped.

> Because nobody knows what that would mean.

> >This way, rather than typing 'my' everywhere, one could just type the
> >ocassional 'our' and assume everything else is local (er, my'd).
> But local to what?  The file? The innermost block in which it appears?
> Neither of those are sensible.

If the pragma is the equivalent of inserting an implicit "my" at the
first appearance of each variable name which is not 'local' or given an
explicit package), then I'd vote it as fairly sensible.

The semantics of the implicit "my" would, of course, depend on the
position of the declaration in the same way as the explicit version.
Obvious tweaks are needed; thus saying "$x[1]=2" would be equivalent to

Whether such a pragma would be a Good Thing is another question. I'd
vote against it on grounds of extra obfuscation for comparitively little
benefit.

Ian



Sun, 28 Sep 2003 16:51:29 GMT  
 We have 'use strict' and 'my', and now 'our', but no 'use local-scope' - why?

Quote:




> > >I've long been baffled that there is no pragma to automatically declare
> > >all variables as default locally-scoped.

> > Because nobody knows what that would mean.

> > >This way, rather than typing 'my' everywhere, one could just type the
> > >ocassional 'our' and assume everything else is local (er, my'd).

> > But local to what?  The file? The innermost block in which it appears?
> > Neither of those are sensible.

> If the pragma is the equivalent of inserting an implicit "my" at the
> first appearance of each variable name which is not 'local' or given an
> explicit package), then I'd vote it as fairly sensible.

This was done to death on perl6-language, I think.  The problem is
that code like

  sub sum {

      $sum += $x
    }
    $sum
  }

would return 0 (they're 2 different C<$sum>s!).

And of course adopting *any* implicit `my' proposal means you can't
catch variable name mistakes, because when you mention $Fo0 in some
inner scope it assumes you really didn't want $FOO.  So why bother?

[...]

--

Compugen Ltd.          |Tel: +972-2-5713025 (Jerusalem) \ We recycle all our Hz
72 Pinhas Rosen St.    |Tel: +972-3-7658117 (Main office)`---------------------
Tel-Aviv 69512, ISRAEL |Fax: +972-3-7658555    http://3w.compugen.co.il/~ariels



Sun, 28 Sep 2003 21:59:16 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. What is pseudorandommy @chars=('a'..'z','A'..'Z','0'..'9','_');

2. How can I use SQL in Quik report?

3. RTE 200 and upgrade questions

4. Using File::Find with 'use strict'

5. using 'use strict' to detect errors

6. using 'strict' and 'format'

7. 'Document contains no data'...still having problems

8. Info.

9. REG: Win31.tpu

10. unpack('x10','')

11. getservbyname('smtp','tcp') Problem

12. split on ':', but not '\:'

 

 
Powered by phpBB® Forum Software