Re: small code smell
Bram Moolenaar <[email protected]>
| Newsgroups | gmane.comp.tools.aap.devel |
|---|---|
| Message-ID | <[email protected]> |
Tim Hemel wrote:
> One suggestion for the Agide code (and perhaps the aap code in general):
>
> I see a lot of if statements which try to find out what os is used:
>
> if os.name == "posix":
> ...
> elif os.name in [ ...]:
> ...
>
>
> I think the code would be more readable if these differences where contained
> in a separate OS class.
>
> class OperatingSystem:
> def spawn(self,cmd):
> pass
> def stillRunning(self,proc):
> pass
>
>
> class PosixOperatingSystem(OperatingSystem):
> def spawn(self,cmd):
> ....
>
> class WindowsOperatingSystem(OperatingSystem):
> def spawn(self,cmd):
> ....
>
> class UnknownOperatingSystem(OperatingSystem):
> def spawn(self,cmd):
> raise UnknownOperatingSystemError;
>
>
> then, in the beginning of the program, you let a little factory function or
> method create this object:
>
> def createOperatingSystem():
> if os.name == "posix":
> return PosixOperatingSystem()
> elif os.name in [ 'dos', ... ]:
> return WindowsOperatingSystem()
> else:
> return UnknownOperatingSystem()
>
>
> This would make the code somewhat cleaner IMO.
For some places this would indeed be cleaner. But in other places you
are taking code out of the context of where it's invoked and dump it in
a class for the operating system. I think it should only be done for
generic things that can be invoked from several places.
--
ARTHUR: (as the MAN next to him is squashed by a sheep) Knights! Run away!
Midst echoing shouts of "run away" the KNIGHTS retreat to cover with the odd
cow or goose hitting them still. The KNIGHTS crouch down under cover.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
\\\ Project leader for A-A-P -- http://www.A-A-P.org ///
\\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html ///
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf