Class or Dictionary?

Martin De Kauwe mdekauwe at
Sat Feb 12 01:24:56 EST 2011


You make some good points and I don't disagree with you. The code is
just a transfer from some older c++ code which had all sorts of
windows menus etc, which isn't required and would make it impossible
to run (again and again). It is not an especially complicated model,
and no doubt there are bugs (though has been used widely for 20

Regarding customisation, in this case it is not a big deal. The way
the code was (arguably poorly) written everything was declared
globally. So in fact by using the .INI file to hold all of them I am
probably saving myself a lot of time and I get away from globals. Most
of those parameters are things I won't change, so I take your point
but I see no issue in having the option frankly (and it is done so
there is no effort now!).

Ordinarily I might do what you said and having method/func calls with
all the params like that, but I felt it was making the code look very
untidy (i.e >5 vars with each call and needing to return > 5 vars). I
then decided it would be better to pass a (single) dictionary or class
object (not sure of correct word here) and I think by referencing it,
e.g. params.light_ext_coeff it is as clear as passing all the values
individually (i.e. you can track where the values came from). I am
happy with this at any rate. Moreover it is what I am used to doing in
C, where I would pass a single structure containing the necessary
values. I also think this is quite standard? I am sure to interface
with scientific libraries (such as GNU GSL) you pass structures in
this way, I was just adopting this method.

The point of this posting was just to ask those that know, whether it
was a bad idea to use the class object in the way I had or was that
OK? And if I should have just used a dictionary, why?


More information about the Python-list mailing list