[Tutor] Function Programming Style

Alan Trautman ATrautman@perryjudds.com
Mon Jun 30 12:49:52 2003


Kai,

While is seems like a lot of extra typing the SET methods are normally kept
separate unless setting on value is dependant on the other. Then as you
program grows you can build functions that use the many smaller set
functions to create changes in all the required values. In addition Python
does not require set or get and (boy I hate this word) "generally" would not
be used if the value does not need to be checked or a secondary value needs
to be changed based on this change. What do that mean in English? I the
variable is an internal (no user can change) state marker the use of get/set
is not necessary and may just be extra lines of code. However, if your set
function can be accessed at three different points and 3 different contexts
then I would write a base set function, and additional set functions that
handle all of the contexts using that first small function. You as the
programmer will know that the function handles all error trapping and works
correctly so that if you base parameters don't change you should not have to
revisit it.

In addition, if you combine all of your set functions into on gigantic
function it will be much harder to debug and/or add features.

HTH,
Alan

Hi,

my first bigger Python program led me think about the following problem:

I have to set informations and defined appropriate get and
set-functions eg. set_title, get_title, set_date, get_date. Now I
wonder, what to do, if I have to do something with the arguments passed
to the function. Maybe then a function like set(what, value) would be
better?

def set_title(value):
	modify(value)
	title = value

def set_date(value):
	modify(value)
	title = value
VS:

def set(what, value)
	modify(value)
	if what==title
		title = value
	elif what==date
		date = value

Regards, Kai
-- 
* mail kai.weber@glorybox.de
  web http://www.glorybox.de
  pgp 0x594D4132

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor