On Sunday 26 April 2009 07:19:54 Steve wrote: > 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.
Cool. Regarding the rest, I've rejigged your reply slightly to make my replies make more sense... > > 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. This is where I confess a piece of ignorance. I wasn't actually aware that named arguments applied to non-optional args. ie I didn't realise that this worked: >>> def say(start, finish): ... print start, finish ... >>> say(start="hello", finish="world") hello world >>> say(finish="world", start="hello") hello world Strange the corners of a language you use for years that you miss :-) However, I suspect I did see it a long time back and may've discounted it due to this behaviour: >>> def say(start, finish, **kwargs): ... print kwargs ... >>> say(finish="world", start="hello") {} Moving on... > > 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 thought that might be the case. > I don't necessarily find > value in the more explicit parameters passed to the super().__init__ > call. [More on that after a quick question] ... > 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). Knowing now that named arguments apply to non-optional args, I'd say that this looks good. Generally speaking we've tried to have kamaelia's base compatibility match that as to when generators were first added to python - ie 2.2.late - specifically because that's the version of python on Nokia Series 60 phones. However, as time goes on I'm more thinking that if Nokia don't support their own phones by updating the python version, I see little reason too either... and jumping Kamaelia's support to 2.5 onwards by default. (Not suggesting 2.6 at present since there's a wide variety of libs we use that are still at 2.5 as well) > 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 approach does look like a good alternative. In a more concrete fashion, I've taken the components you've put forward and put them onto a new branch for potential merge. Obvious Q, Where have I put them? Kamaelia/Apps/SA/ - As a namespace for holding any Kamaelia code you put forward. It should be instantly obvious that you can replicate this package locally in your own local VCS, and push updates to this directory to us, unless you want direct SVN access to this directory. Kamaelia/Apps/SA/__init__.py - Obvious purpose. Kamaelia/Apps/SA/Chassis.py - This contains the TTL component. The reason I've called this a chassis is because just like a real world chassis, in order for this component to function, you need to plug a real world component into it for it to make sense. There's a few FIXMEs in that code that I've added there need some thought about how to solve (which I'm happy to resolve), but noted Kamaelia/Apps/SA/DSL.py - I've placed the DataSink component in here. The idea being that it ties in with an idea I've had for a while. Out of many components created in kamaelia, a fair number relate to plumbing or building shapes out of components - which form a domain specific language for concurrency. Some are things like graphlines/pipelines/etc, some are things like data source, and data sink is comparable. Kamaelia/Apps/SA/Time.py - In here I've placed SingleTick and PeriodicTick. Whilst I note there that there's a more generic concept lurking, I'm happy with the code you've written there - especially with this staging namespace. Branch URL: http://kamaelia.googlecode.com/svn/branches/private_SA_Utils Browse URL: http://code.google.com/p/kamaelia/source/browse/branches/private_SA_Utils/Kamaelia/Kamaelia/Apps/SA/ Incidentally, I view this namespace Kamaelia.Apps.SA - as owned by you - so if you don't like the names here, please let me know. If you're happy with these as a starting point though, let me know, and I'll merge those into trunk in that location. If you're not and want to modify it, please either mirror locally and send patches or let me know your google code ID, and I'll grant you access for editting what is essentially your code :-) (This is part of a wider plan intended to make code contribution simpler, easier, more diverse and less dependent on me - with more than a little flagrant idea stealing from CPAN/CTAN :-) Regards & many thanks :) Michael. -- http://yeoldeclue.com/blog http://twitter.com/kamaelian http://www.kamaelia.org/Home --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---