[Python-ideas] Reducing language complexity

Steven D'Aprano steve at pearwood.info
Wed Dec 25 11:19:32 CET 2013


On Wed, Dec 25, 2013 at 12:03:37PM +0300, anatoly techtonik wrote:

> Unfortunately, the first message with "Language complexity formula" is
> deemed to be "not python related" by moderators, so this mail landed
> without necessary context. Without understanding what adds to the
> language complexity, this discussion looks useless.

You should write a blog post about the language complexity formula. That 
way people who are motivated by it can read it, while those who don't 
won't need to be bothered by an off-topic discussion on something which 
isn't specific to Python.

As for your suggestion to "prepare" readers for "advanced" concepts:

    using generators as yield


who defines what counts as "advanced"? Python for-loops iterating over 
sequences may seen advanced to a C or Pascal programmer expecting to 
write code like "for i := 1 to 50 do process(seq[i]);". Exceptions may 
seem advanced to Java programmers. Even functions may seem terribly 
advanced to those who have never programmed before. (And I've seen 
them on the tutor list.)

How do you expect this "using" statement to actually help the reader? 
I have never, ever, not even as a total newbie knowing next to nothing 
about Python (or any other language) been in a position where I was 
reading code, came up on a keyword, function or idiom I didn't 
understand, and thought "Oh, if only this was declared at the beginning 
of the file, I would have understood it better!".

On the other hand, I would feel pretty annoyed if I came across a file 
containing

    using flibbit as smudgeon

at the start, spent a lot of time reading up on flibbit and smudgeon, 
then came back to the file and discovered that the hours I had spent was 
completely unnecessary because the part of the file I cared about didn't 
actually use flibbit or smudgeon.

If a reader comes across "advanced" code they don't understand:

def increment(values):
    for value in values:
        yield value+1

isn't it pretty trivial for them to ask "what does yield do?". You 
don't need a "using" statement to lead them to the right search 
terms. If you think the search terms aren't obvious enough and want to 
write code aimed at the least-experienced reader, just use a comment, 
and put it right where it is needed:

# Keywords: yield, generator, Python.
# http://link-to-your-blog-explaining-this
def increment(values):
    for value in values:
        yield value+1


-- 
Steven


More information about the Python-ideas mailing list