small code smell

Tim Hemel <[email protected]>
Newsgroups gmane.comp.tools.aap.devel
Message-ID <[email protected]>
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.


Tim

-- 
Zen Microsystems: we're the om in .commmmmmmmm...


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.