Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31879

Re: A desperate lunge for on-topic-ness

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'newbie': 0.05; 'c++,': 0.07; '22,': 0.09; 'brace': 0.09; 'cleaned': 0.09; 'declarations': 0.09; 'etc).': 0.09; 'python:': 0.09; 'looked': 0.10; 'static': 0.13; 'language': 0.14; '(but': 0.15; '(like': 0.15; 'languages.': 0.15; "'this',": 0.16; 'closures': 0.16; 'confusion': 0.16; 'declaration': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'function).': 0.16; 'globals.': 0.16; 'impractical': 0.16; 'keyword.': 0.16; 'nesting': 0.16; 'oct': 0.16; 'php:': 0.16; 'scope,': 0.16; 'scope.': 0.16; 'there?': 0.16; 'trap': 0.16; 'variables),': 0.16; 'works"': 0.16; 'later': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'exists': 0.17; 'odd': 0.17; 'typing': 0.17; 'variables': 0.17; 'variable': 0.20; 'do.': 0.21; 'error.': 0.21; 'received:209.85.214.174': 0.21; 'explicit': 0.22; "i'd": 0.22; 'flexibility': 0.23; "python's": 0.23; "i've": 0.23; 'connected': 0.24; 'allows': 0.25; 'header:In-Reply-To:1': 0.25; 'separate': 0.27; 'object,': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'all.': 0.28; "d'aprano": 0.29; 'declared': 0.29; 'overhead': 0.29; 'python).': 0.29; 'steven': 0.29; 'objects': 0.29; 'unlike': 0.30; 'function': 0.30; 'anywhere': 0.33; 'function.': 0.33; 'limitations': 0.33; 'skip:j 20': 0.33; 'to:addr:python-list': 0.33; 'languages': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'next': 0.35; 'but': 0.36; 'compare': 0.36; 'does': 0.37; 'skip:z 10': 0.37; 'quite': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'there,': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'called': 0.39; 'subject:-': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'most': 0.61; 'time,': 0.62; 'between': 0.63; 'close': 0.63; 'different': 0.63; 'levels': 0.66; 'introduce': 0.80; '"just': 0.84; "'with'": 0.84; 'calls,': 0.84; 'hardly': 0.84; 'local,': 0.84; 'pike': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=0C2gquq11dEPLDJJSjlR/htTJiQyFAi74G2TsIiu9y4=; b=bOwKphnmcUeW0YboOiM0C9qcmYNeGXWimAvGhD+xtcHXVAOcojjklIZ4nS1KTBTBah RcF/qVlVOIWsYguKfsrWSEsBkBhdvR+juVepAaW4sIEuDY2ASA99Y06Zgpm8SRolN4OS drIisHrPPBHmvRCE+/ZUP8LYbe6upiWT1UVYbEWbnnlgJDWluMwq/yfMERx9xt7XE7Bd gCDduEDIjLE/HKSumfTuBC865XZoV+hlOG5UQ2zAZSBBkCCH7oy6RWVBW4W2VA1D7hnU rAJGf20Uq35EZX+GG2CfuydDWH4Q/2/AJP2GcWL4pCyiziocy4ltKUBCnJzlL47XogYu dEMg==
MIME-Version 1.0
In-Reply-To <5084e819$0$29897$c3e8da3$5496439d@news.astraweb.com>
References <mailman.2501.1350638446.27098.python-list@python.org> <5081d0c3$0$30003$c3e8da3$5496439d@news.astraweb.com> <mailman.2543.1350692652.27098.python-list@python.org> <k5ubs7$p6b$1@reader1.panix.com> <5083ad3e$0$29978$c3e8da3$5496439d@news.astraweb.com> <mailman.2582.1350811250.27098.python-list@python.org> <5083c7da$0$29978$c3e8da3$5496439d@news.astraweb.com> <mailman.2588.1350819797.27098.python-list@python.org> <508448c6$0$29978$c3e8da3$5496439d@news.astraweb.com> <mailman.2601.1350850942.27098.python-list@python.org> <5084e819$0$29897$c3e8da3$5496439d@news.astraweb.com>
Date Mon, 22 Oct 2012 18:03:39 +1100
Subject Re: A desperate lunge for on-topic-ness
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2618.1350889423.27098.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1350889423 news.xs4all.nl 6874 [2001:888:2000:d::a6]:60962
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31879

Show key headers only | View raw


On Mon, Oct 22, 2012 at 5:30 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> For languages without static types, what other reasons for declaring
> variables are there?

The main one is scope nesting. Compare a few different languages.

Python: If you don't declare, it's global if you don't rebind it, but
local if you do. You may declare variables as global or nonlocal.

PHP: If you don't declare, it's local, but functions are in a separate scope.

C: If you don't declare, it's looked for in some broader scope. If
it's not declared in any scope, error.

All three approaches make reasonable sense. The PHP one is perfectly
consistent, but would be hopelessly impractical if all your function
names had to be marked off as globals. (Plus PHP has superglobals,
with their own Marvellous mess.) Python's system "just works" most of
the time, but can introduce yet another trap for the unsuspecting
newbie who doesn't understand the difference between rebinding and
mutating; I've not looked into multiple levels of closures but I
suspect there'll be odd limitations there, as there's only one
"nonlocal" keyword. The C style has administrative overhead (requiring
explicit declarations for all variables), but allows full flexibility
(variables having narrower scope than entire functions, infinite
nesting of scopes, etc).

Incidentally, variable declarations don't have to be connected with
static typing. JavaScript/ECMAScript simply has 'var x;' to declare
that x exists in this function. But it's hardly a language that I'd
hold up as a shining example; a var declaration anywhere in a function
makes that variable name local to that entire function. There's
actually no block scoping at all. And then there's the whole confusion
of the global object, 'this', and 'with' statements...

You knew I was going to cite it sooner or later :) Pike has true block
scoping, though unlike C++, Pike does not guarantee that destructors
will be called immediately at the close brace (but zero-reference
objects will be cleaned up, including destructor calls, at the next
function return - even if not the current function). Variables can be
mostly-statically-typed, or can be declared as 'mixed' and be rebound
freely (like in JS and Python). So scoped variable declarations and
static typing are quite orthogonal.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: A desperate lunge for on-topic-ness Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-10-19 11:21 +0200
  Re: A desperate lunge for on-topic-ness Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-19 22:14 +0000
    Re: A desperate lunge for on-topic-ness Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-10-19 20:23 -0400
      Re: A desperate lunge for on-topic-ness Grant Edwards <invalid@invalid.invalid> - 2012-10-20 14:18 +0000
        Re: A desperate lunge for on-topic-ness Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-10-20 15:10 -0400
        Re: A desperate lunge for on-topic-ness Walter Hurry <walterhurry@lavabit.com> - 2012-10-20 20:02 +0000
        Re: A desperate lunge for on-topic-ness David Robinow <drobinow@gmail.com> - 2012-10-20 16:02 -0400
        Re: A desperate lunge for on-topic-ness Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-21 08:07 +0000
          Re: A desperate lunge for on-topic-ness Chris Angelico <rosuav@gmail.com> - 2012-10-21 20:20 +1100
            Re: A desperate lunge for on-topic-ness Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-21 10:00 +0000
              Re: printing (was: A desperate lunge for on-topic-ness) Tim Chase <python.list@tim.thechases.com> - 2012-10-21 06:03 -0500
              Re: A desperate lunge for on-topic-ness Chris Angelico <rosuav@gmail.com> - 2012-10-21 22:43 +1100
                Re: A desperate lunge for on-topic-ness Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-21 19:11 +0000
                Re: A desperate lunge for on-topic-ness Grant Edwards <invalid@invalid.invalid> - 2012-10-21 19:23 +0000
                Re: A desperate lunge for on-topic-ness Roy Smith <roy@panix.com> - 2012-10-21 16:19 -0400
                Re: A desperate lunge for on-topic-ness Chris Angelico <rosuav@gmail.com> - 2012-10-22 07:38 +1100
                Re: A desperate lunge for on-topic-ness Chris Angelico <rosuav@gmail.com> - 2012-10-22 07:22 +1100
                Re: A desperate lunge for on-topic-ness Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-22 06:30 +0000
                Re: A desperate lunge for on-topic-ness Chris Angelico <rosuav@gmail.com> - 2012-10-22 18:03 +1100
                Re: A desperate lunge for on-topic-ness Roy Smith <roy@panix.com> - 2012-10-22 08:29 -0400
                RE: A desperate lunge for on-topic-ness "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-22 20:48 +0000
                Re: A desperate lunge for on-topic-ness Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-22 16:02 -0600
                Re: A desperate lunge for on-topic-ness Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-10-22 21:39 -0400
                Re: A desperate lunge for on-topic-ness Joshua Landau <joshua.landau.ws@gmail.com> - 2012-10-23 08:35 +0100
                Re: A desperate lunge for on-topic-ness Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-23 10:50 -0600
                Re: A desperate lunge for on-topic-ness Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-23 22:34 +0000
                Re: A desperate lunge for on-topic-ness Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-23 17:24 -0600
                Re: A desperate lunge for on-topic-ness Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-24 00:04 +0000
          Re: A desperate lunge for on-topic-ness Gene Heskett <gheskett@wdtv.com> - 2012-10-21 07:08 -0400
          Re: A desperate lunge for on-topic-ness Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-10-21 12:42 -0400
        Re: A desperate lunge for on-topic-ness DJC <djc@news.invalid> - 2012-10-21 15:06 +0100
    Re: A desperate lunge for on-topic-ness Tim Chase <python.list@tim.thechases.com> - 2012-10-19 22:27 -0500
      Re: A desperate lunge for on-topic-ness rusi <rustompmody@gmail.com> - 2012-10-20 00:35 -0700
    Re: A desperate lunge for on-topic-ness Roy Smith <roy@panix.com> - 2012-10-20 16:37 -0400
      Re: A desperate lunge for on-topic-ness Walter Hurry <walterhurry@lavabit.com> - 2012-10-21 21:58 +0000

csiph-web