Help me pick an API design (OO vs functional)

Michael Herrmann michael.herrmann at getautoma.com
Wed Mar 27 13:23:57 CET 2013


On Wednesday, March 27, 2013 12:44:49 PM UTC+1, Chris Angelico wrote:
> ...
> Not seeking to advocate this particular option, but it would be
> possible to make a single wrapper for all your functions to handle the
> focus= parameter:
> 
> def focusable(func):
> 	@functools.wraps(func)
> 	def wrapper(*args,focus=None):
> 		if focus: focus.activate()
> 		return func(*args)
> 	return wrapper
> 
> Then you just decorate all your functions with that:
> 
> def write(string):
>     # do something with the active window

Hi, sure, I wouldn't have copy-pasted the code and of course there are techniques to avoid code duplication. It's not so much what I'm worried about. What I'm worried about is that the concept of window-switching gets "smeared" over several other not-really related concepts such as clicking and typing. I feel it violates orthogonality: http://www.artima.com/intv/dry3.html is the best freely available resource I could find but I think it's best explained in The Pragmatic Programmer http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X.

Michael
www.getautoma.com



More information about the Python-list mailing list