Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>:

> But I'm not sure that there is a good reason to put the class definitions 
> inside the __init__ method. That means every time you create a new 
> StateMachine instance, the classes have to be re-created.
>
> [...]
>
> It will be much more efficient if you pull all the Idle, etc. classes out 
> and make them top-level global classes.
> [...]
> But then the closure over sm won't work...

Precisely.

As for effiency, I don't know if it is more efficient to create ad hoc
classes or ad hoc instances; might be a tossup in CPython.

> Since in this example you've actually got significant behaviour in the
> states, they aren't just symbols, and some sort of solution along
> these lines (whether you use multiple inner classes or not) is
> appropriate.

That inner class solution is an alternative to the symbol approach. In
the absense of a switch statement, the inner class has lots going for
it.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to