[Tutor] Code structure help
mdekauwe at gmail.com
Fri Mar 11 17:06:47 CET 2011
I think your question is appropriate for both lists, it just wasn't sexy
enough for anyone on c.l.py to answer ;)
what is not sexy about modelling plant carbon uptake ;P
> pg = PlantGrowth(self.control, self.params, self.state,
> self.fluxes, self.met_data)
I'd prefer your code to be even more verbose here; no two-letter variables
for anything that is non-generic.
ok so a more thorough name then? I had seen class instances used before with
> # plant growth
> pg.grow(project_day, self.date, leafnc)
With the construction in mind that is actually
Sorry don't get this?
> # plant growth
> plant_growth.grow(project_day, self.date, leafnc)
but plant_grows.grow() does not make a lot of sense, and the comment is
superfluous as it just undoes the abbreviation instead of explaining what is
Yep sorry I haven't gone through and finished all the comments, some of them
were placeholders! Agreed grow isn't the best name
> # calculate model decay rates
A lot of methods don't take any arguments and return nothing. I'm guessing
that they modify the state that you passed to the initializer. I prefer
these modifications to be explicit if feasible, e. g.
state = dc.decay_rates(state)
where of course state is a placeholder for the actual variables that are
necessary to do the calculations.
yes well i guess that is one of the issues - two objects state and fluxes
are modified throughout. So you think it is better to pass these to the
methods rather than to the class constructors? If i do it that way I
potentially have to then pass it throughout a number of methods in other
classes. The way I set it up, I could call it though the self statement,
e.g. self.fluxes.some_variable in a various class methods.
The big picture? I'll leave that for someone else.
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
View this message in context: http://old.nabble.com/-Tutor--Code-structure-help-tp31124923p31126370.html
Sent from the Python - tutor mailing list archive at Nabble.com.
More information about the Tutor