[Tutor] Benefit/Disadvantage to storing data as dictionary vs. in a class

Walter Prins wprins at gmail.com
Fri Jun 1 18:07:11 CEST 2012


Hi Adam,

On 1 June 2012 15:45, Adam <amgaweda at gmail.com> wrote:
> Is there any benefit to creating a class for each bucket (with an 'update'
> method) vs. storing those variables as a dictionary with the 'Room' class as
> {'var':0, 'avg': 0, 'sd':0, 'readings':[]} and having the Room class hold
> the update function; not so much from good programming practices, but more
> attempting to number of resources the class will be using.

I'd submit that worrying about resource usage above/beyond/to the
exclusion of worrying about the easy maintenance and readability of
your code at this apparently early stage may be a sign of premature
optimisation.  IMHO the difference in resource usage is going to be
fairly negligible either way and you should lean towards prioritising
keeping your code easy to read and easy to maintain at this point.
How many rooms/buckets are we talking about anyway?  (I might add I
like Adam also find the triple indexed self.rooms[z][12][85] obscure
and would prefer even just say a method with positional and/or names
parameters.  But I suppose I may feel differently if I worked with
your API for a while. :) )

Walter


More information about the Tutor mailing list