On Sat, 29 Sep 2012, Wayne Werner wrote:

On Sat, 29 Sep 2012, Oscar Benjamin wrote:
On Sep 29, 2012 2:25 AM, "Alan Gauld" <alan.ga...@btinternet.com> wrote:
>
> On 28/09/12 21:32, Jim Apto wrote:
>
>> I'm relatively new to python, and was asked to program a lotka-volterra
>> model (predator and prey relation) simulator.
>
>
>> x represents prey population
>> y represents predator population
>
>
> so use names that say so, like preyPop and predatorPop
> Its only a few extra letters typing but makes things much more readable.

As a mathematician I'd have to disagree with you there Alan. This model
already has an established notation:

Regardless of established notation, unless only mathematicians will be reading
the code, and only those intimately familiar with the equation, it makes much
more sense to use meaningful names.

And lest I sound like I'm completely ignoring the mathematical aspect - what *does* make sense to do is this:

x = prey_popluation
y = pred_population

# insert mathematical formula here.

This satesfies all parties:

1) It gives us programmers nice, meaningful names
2) It gives mathematicians the formula that screams "FORMULA!"
3) It clearly separates the math-y bits from the program-y bits.

Because let's face it,

x = float(input("Starting Prey Population: "))

isn't exactly something you find in (most) math classes. And I think clearly separating concerns is always a good thing.

-Wayne
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to