On Thursday, May 28, 2015 at 11:59:36 AM UTC-5, Marko Rauhamaa wrote:
> Ian Kelly <ian.g.ke...@gmail.com>:
> > I think I would be more inclined to use enums. This has the advantages
> > of not creating a new set of state classes for every connection
> > instance and that each state is a singleton instance, allowing things
> > like "if self.state is SMTPConnectionState.IDLE". It could look
> > something like this:
> >
> > class SMTPConnectionState(Enum):
> >
> >     class IDLE:
> >         @classmethod
> >         def handle_command(cls, conn, cmd):
> >             # ...
> >
> >     class SPF_HELO:
> >         @classmethod
> >         def terminate(cls, conn):
> >             # ...
> 
> Really, the main expressive choice is whether you use an inner class
> (and get the advantages of a closure) or an outer class (and get
> potential performance advantages).

Can you tell me: What is the advantage of a closure here?

Also:  why wouldn't you simply put your state classes at the outer scope (i.e. 
module-level) of your module so that they are clear to anyone else who want to 
use the module?  Presumably these classes are for making your 
SMTPServerConnection object more useable, not to hide these state-classes from 
the users.

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

Reply via email to