[PEAK] removing adaptions

Phillip J. Eby pje at telecommunity.com
Mon Oct 25 17:54:28 EDT 2004


At 10:36 PM 10/25/04 +0200, Gabriel Jägenstedt wrote:

>one might note that the purpose of lingo in the bin is that it should
>always be supplied with a string as first argument(pub.language) which
>tells us which language to use. This is most often supplied va the
>commandline but I want it to be possible to be changed if one wants.
>(If it weren't for this fact there would be no problem)

 From the bits you posted, adaptation has nothing to do with what your code 
is trying to do, and the code would be cleaner if you took it out.

As far as I can see, you're abusing adaptation from string->ILang to 
replace a simple dictionary lookup, and you're abusing adaptation from 
modules to various other interfaces in order to replace a simple attribute 
retrieval.  In other words, I'd replace uses of your 'lingo' function with, 
e.g.:

      parser = language_modules['english'].ParserClass()

Now, I *might* define an ILanguageModule interface to *document* what 
attributes a language module should have, like the fact that 'ParserClass' 
should be a factory that creates 'IParser' instances.  I might even have 
the loader for 'language_modules' try to adapt the modules to 
ILanguageModule, as a double-check that they have at least declared 
themselves compatible.

But, at least from what you've posted, I see no reason to use any of the 
other adaptation that's taking place, as it's not really adaptation 
anyway.  Adapting from a string to a language module makes no sense.  The 
string is the *name* of a language, not a language!  It needs some context 
to go with it.  Either you pass a language name to a collection of language 
modules, or you pass the collection to the name to request a lookup.  And, 
unless you have special needs for the behavior of the language name, it's 
simpler just to use a string in the first place.




More information about the PEAK mailing list