Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101848
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Keen eyes |
| Date | 2016-01-17 22:32 +1100 |
| Message-ID | <mailman.60.1453030378.15297.python-list@python.org> (permalink) |
| References | (2 earlier) <7625bba2-5c2d-4d28-8b6a-30ec7b490089@googlegroups.com> <569b3e53$0$1615$c3e8da3$5496439d@news.astraweb.com> <CALwzid=8RSUQzsicoBac01LXDWs9BUoJ8atnfB4_ag7PmXXC+Q@mail.gmail.com> <mailman.56.1453019131.15297.python-list@python.org> <n7ft2d$f7b$1@dont-email.me> |
On Sun, Jan 17, 2016 at 10:17 PM, BartC <bc@freeuk.com> wrote: > On 17/01/2016 08:25, Chris Angelico wrote: >> >> On Sun, Jan 17, 2016 at 6:37 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote: >>> >>> Technically it defaults to non local. The var statement allocates a >>> variable within the current scope. Otherwise it searches up the chain of >>> parent scopes for a matching variable... >> >> >> This far, it's exactly the same as C. >> >>> ... terminating at the global scope. >> >> >> This is the bit that gets ridiculous. Undeclared variables in C are >> compile-time errors. Undeclared variables in JS are implicit globals. >> This is stupid. > > > My own language is something in-between. If a name is not declared locally, > it will look at more global scopes. If nothing is found, it will > auto-declare a local. > > So the JS bug wouldn't occur. However, there is the problem that, given a > perfectly working function with implicitly locals, at some point in the > future someone could introduce a global that will clash with the name of a > local, and screw things up. > > Because of that, the Python scheme is better on the whole. The only issue is > that sometimes you think you're assigning to a global, but it's really a > local if you forget the 'global' declaration within the function. The Python scheme makes a lot of logical sense. The C scheme (declare everything, otherwise it's an error) makes a lot of logical sense. I've never seen a hybrid scheme that makes as much sense as either of the above. In both Python's and C's ways of doing things, you can look at a single function and know which names are local and which are external. Have fun trying to share code snippets without knowing full context... ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Keen eyes jonas.thornvall@gmail.com - 2016-01-16 14:23 -0800
Re: Keen eyes Chris Angelico <rosuav@gmail.com> - 2016-01-17 09:30 +1100
Re: Keen eyes jonas.thornvall@gmail.com - 2016-01-16 14:55 -0800
Re: Keen eyes jonas.thornvall@gmail.com - 2016-01-16 15:25 -0800
Re: Keen eyes Steven D'Aprano <steve@pearwood.info> - 2016-01-17 18:10 +1100
Re: Keen eyes Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-17 00:37 -0700
Re: Keen eyes Paul Rubin <no.email@nospam.invalid> - 2016-01-16 23:52 -0800
Re: Keen eyes Chris Angelico <rosuav@gmail.com> - 2016-01-17 19:25 +1100
Re: Keen eyes BartC <bc@freeuk.com> - 2016-01-17 11:17 +0000
Re: Keen eyes Chris Angelico <rosuav@gmail.com> - 2016-01-17 22:32 +1100
csiph-web