A counter-proposal to __future__ in PEP 236

Lloyd Sommerer lsommerer at sewardweb.com
Fri Mar 2 10:38:04 EST 2001


Speaking as someone who is very new to python (3 weeks) and has only
written two programs, using a colon in this manner would have been
confusing.  Right now, my understanding is that the colon exists (apart
from slicing) only to allow statements to follow immediately after a
looping or control structure (on the same line).

This is obviously very distinct from its use with slices.  But it seems
reasonable to me that new python programmers would wonder if this:

directive: nested_scopes

might be equivalent to:

directive:
     nested_scope

I should also point out that the "from  __future__ import..." is also
confusing to a newbie, but others have said that already.

Lloyd Sommerer

Alex Martelli wrote:

> "Martin von Loewis" <loewis at informatik.hu-berlin.de> wrote in message
> news:j47l29lpo8.fsf at informatik.hu-berlin.de...
>     [snip]
> > In this implementation, directive is only considered as a keyword if
> > it appears at the beginning of the module. Therefore, code that
> > happens to use directive as an identifier will not break (unless it
> > assigns to directive as the first thing in the module).
> >
> > I'd appreciate any comments as to whether this directive statement is
> > better or worse for the purpose of indicating that nested scopes are
> > used in a module.
>
> It's indisputably much more explicit and direct.  Recycling
> 'from/import' to mean something very different than other uses
> of from/import is subtle and cute.  This implies a huge plus
> for the 'directive' patch.
>
> Yes, 'directive' does theoretically imply possible code
> breakage -- although, if it were possible to further
> special-case things so that the directive statement
> always took TWO or more directive-words, as in, e.g.
>
> directive nested scopes
>
> or
>
> directive simple scopes
>
> and/or took a colon, e.g.
>
> directive: scopes nest
>
> or
>
> directive: no nesting
>
> it might perhaps be possible to avoid breaking ANY code
> that currently might be working by any stretch of the
> imagination (I have not checked how hard it might be to
> look-forward in the lexer so that only directive-colon
> triggered the new keyword-token -- just reasoning in
> the abstract).  [It seems to me the colon would not
> damage readability at all here -- on the contrary].
>
> Even if the theoretical breakage of some hypothetical
> old module starting with
>     directive = 23
> or
>     directive, floopres = 23,42
> was to be the price of avoiding the cuteness of
> 'from/import' "overloading", I would still vote for
> directive (or, rather, against the overloading thing)
> if I did have a vote in the matter.  Such special cases
> and cuteness are overdone in other languages (C++ and
> its different uses of 'static' come to mind...), and
> they're a bear to teach to newbies.  The _semantics_
> of PEP 236 are a great idea; I do earnestly hope there
> is some way, ANY way, to avoid its syntax, and this
> 'directive' idea gives me a glimmer of hope...!
>
> Alex




More information about the Python-list mailing list