Hi Michael,

Thank you very much for such a carefully thought out reply.  I
particularly enjoyed your examples illustrating your thought process.
It shed light on considerations which I had not previously thought
about.  Clearly it is a balancing act between what is best for
simplistic usages like I'm accustomed to and what scales cleanly for
more enterprise style use cases.

> So this led me to this alternative set of possibilities:
>
> class TCPClient(Axon.Component.component):
>    delay = 0
>    connect_timeout = 60
>    def __init__(self, host, port, **kwargs):
>       super(TCPClient, self).__init__(**kwargs)
>       self.CSA = None
>       self.sock = None
>       self.howDied = None
>       self.host = host
>       self.port = port
>
> class Port80Client_Declarative(TCPClient):
>    port = 80
>    def __init__(self, host, **kwargs):
>       port = kwargs.pop("port", self.port)
>       super(Port80Client_Declarative, self).__init__(host, port, **kwargs)
>
> class KamaeliaWebsiteClient_Declarative(Port80Client):
>    host = "www.kamaelia.org"
>    def __init__(self, **kwargs):
>       host = kwargs.pop("host", self.host)
>       super(KamaeliaWebsiteClient_Declarative, self).__init__(host, **kwargs)
>       ...

I do prefer this more explicit alternative.  Mainly it is the more
explicit nature of actually instantiating TCPClient or Port80Client or
KamaeliaWebsiteClient that appeals to me.  I don't necessarily find
value in the more explicit parameters passed to the super().__init__
call. [More on that after a quick question]

> The only downside of all this really is that it prevents this:
>    TCPClient(host="www.kamaelia.org", port="80")

Why is this not possible?  My eyeball interpreter doesn't see any
reason why that would not work with what you've written.

> I have indeed, and as you'll see I've taken your thoughts on board, and I
> think reached a similar conclusion :-)

Thank you very much indeed.  I greatly appreciate your explanations.

May I suggest a slight variant on your proposed alternative?  This
variant retains the more explicit instantiations (__init__ calls from
user code) while allowing a bit of the magic back in for inheritance
(__init__ calls via super).

class TCPClient(Axon.Component.component):
   delay = 0
   connect_timeout = 60
   def __init__(self, host, port, **kwargs):
      super(TCPClient, self).__init__(**kwargs)
      self.CSA = None
      self.sock = None
      self.howDied = None
      self.host = host
      self.port = port

class Port80Client_Declarative(TCPClient):
   port = 80
   def __init__(self, host, **kwargs):
      kwargs.setdefault("port", self.port)
      kwargs['host'] = host
      # Or if >= py 2.4
      # kwargs.update(host=host)
      super(Port80Client_Declarative, self).__init__(**kwargs)

class KamaeliaWebsiteClient_Declarative(Port80Client):
   # this variation moves the default declaration fully into the init
   def __init__(self, **kwargs):
      kwargs.setdefault("host", "www.kamaelia.org")
      super(KamaeliaWebsiteClient_Declarative, self).__init__
(**kwargs)
      ...

This alternative would help users understand the fundamentally
required arguments (from reading or IDE tooltips / autocompletion)
while allowing relatively easy parent initialization.

> Apologies for the delay, but I really did need a holiday ;-) :-)

No worries!  I really need a holiday myself so I can fully appreciate
how necessary some away time can be.

Thanks,
Steve

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"kamaelia" group.
To post to this group, send email to kamaelia@googlegroups.com
To unsubscribe from this group, send email to 
kamaelia+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/kamaelia?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to