[Python-ideas] Before and after the colon in funciton defs.

Carl Matthew Johnson cmjohnson.mailinglist at gmail.com
Thu Sep 22 06:21:45 CEST 2011

Well, now that we're getting down to picking bike shed colors, time to chime in:

blah = static blah

is worse than 

static blah = blah

because it's easier to visually pick out something on the LHS and it's analogous to global/nonlocal. Anything having to do with parens is visually ugly and should be avoided unless absolutely needed for explicitness.

One question I have is how this will work with control flow. This example is works with Python 2.7 and 3.2:

>>> x = 0
>>> def f():
...  if False: global x
...  x = 7
...  return x
>>> f()
>>> x

Presumably static would work the same way? Still, I find this sort of distasteful, since the behavior is a bit surprising to those not familiar with the in's and out's of the compilation model. 

Why not put the static declaration in the argument list, something like:

def f(static l=[]):

And maybe as a shortcut for static NAME=NAME, use just static NAME.

fs = []
for i in range(10):
    def f(static i):
        return i

Looks OK to me.

More information about the Python-ideas mailing list