ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
RE: [Tutor] Function Programming Style
by Alan Trautman other posts by this author
Jun 30 2003 4:47PM messages near this date
[Tutor] sound volume | Re: [Tutor] Function Programming Style
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@[...].de
  web http://www.glorybox.de
  pgp 0x594D4132

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

_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Alan Trautman
Kai Weber

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved