This is really up to your programming style, but I'm of the opinion that 
defining all of the default values in one place keeps maintenance easier.

Of course, if it's done differently elsewhere in your code base, I would aim 
for consistency instead.

Thanks,
Nick Cash

-----Original Message-----
From: python-list-bounces+nick.cash=npcinternational....@python.org 
[mailto:python-list-bounces+nick.cash=npcinternational....@python.org] On 
Behalf Of Dennis Carachiola
Sent: Monday, June 11, 2012 13:38
To: python-list@python.org
Subject: Where to set default data - where received, or where used

I'm programming a project which will use a file to save parameters needed by 
the program.  There are already two previous file formats, each of which can 
only be run by the version of the program which created them.  I'm trying to 
avoid that problem in the future.  To do that, I intend to use a dictionary, 
and default data.  I believe that most new versions will add parameters.

Each version of the program will have reasonable default values for each key in 
the dictionary handled by that version.  If an older file is used, the data 
values in that file replace the keys that exist.
The program then can operate on the values supplied by the older data file and 
the default values.  Conversely, if a newer file is used, the data in the file 
replaces the keys in the dictionary.  The program then simply doesn't access 
the newer data values.  I'm hoping that this will make the file backward and 
forward compatible.

Here's my question.  I could do this by creating the dictionary with the 
default values, then read the file into it.  Or I could use a 'get' with 
default values at the location in the program where those values are used.

>From what I can see, creating the dictionary with default values puts
everything in one place.  While, supplying the default values at the place 
where they're used places the default values nearest the place where actually 
used.

I can't decide on one way over the other.  Can anyone give me some ideas if one 
is a preferred method, or other criteria I've overlooked?

Thanks,

Den
--
http://mail.python.org/mailman/listinfo/python-list


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to