Goto (Posting On Python-List Prohibited)

bartc bc at freeuk.com
Sun Dec 31 11:55:01 EST 2017


On 31/12/2017 15:02, Ben Bacarisse wrote:
> bartc <bc at freeuk.com> writes:

> I think there's a problem with that.  Standard C does not have them, you
> said your language does not implement them properly

(The real problem is I don't remember local functions being used 
anywhere else. It's an idiom I'm not used to and that apparently few 
other people use. Except perhaps in Python where they do to use advanced 
features over simpler ones.)

  and I think you are
> new(ish) to Python.  What language did you try them in?  It may be that
> it was overly complex in that language.  The idea is clean and simple.

It's not simple to implement. Not if you want full access to the 
non-static variables of the containing function(s). It doesn't sound 
that efficient either.

>> So in this case I disagree with dragging in named functions and
>> introducing an extra level of control flow just to avoid duplicating
>> half a dozen lines of code. I would just duplicate those lines (with a
>> comment that they have to match the other set so that they are
>> maintained in sync).
> 
> The suggestion was to use them to avoid gotos.  If duplicating is a good
> idea (and it's a hard line to draw) then we are not talking about the
> same cases.  Given the choice of "dragging in named functions" and
> dragging in named blocks and gotos, I would choose the functions every
> time.

The blocks don't need to be dragged; they are already in place!

It's funny because in c.l.c you're always advocating keep declarations 
as close to the point of use as possible. Here you appear to be saying 
the opposite: taking code away from the primary point of use.

(Which is likely to cause problems if the code includes breaks, or gotos 
if the language has them.)

I think there is a way to solve this pattern via special language 
features, while writing the main code primarily inline and in a natural 
structure, but I haven't found a satisfactory method yet. I don't think 
local functions is it.

(And perhaps a solution lies outside the language such as within an 
editor, to allow sharing of the same block of code in multiple locations.)

-- 
bartc



More information about the Python-list mailing list