[Tutor] Lotka-Volterra Model Simulation Questions
steve at pearwood.info
Sat Sep 29 12:42:10 CEST 2012
On 29/09/12 19:16, Alan Gauld wrote:
> On 29/09/12 09:41, Oscar Benjamin wrote:
>> > 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:
> I did say I had no idea about the original algorithm so yes, if the
>variable names are industry standardised and the people working with the
> code are familiar with them then it may be better to stick with them,
> even if nobody else on the planet understands the resultant code.
One advantage of using single-letter names in a function when the rest of
your module uses descriptive names is that it immediately screams
"mathematical formula". If that means the programmer seeks help from an
expert sooner, that's a good thing :)
> As to using short names to keep things on a single line, there is a huge
>body of research in Comp Science that shows that meaningful names outweigh
>single line expressions every time in terms of reliability, comprehension,
>ease of maintenance etc.
Yes, but "meaningful names" is relative to the reader, and depends on their
familiarity with the topic on hand. To *some* degree, you can overcome a
lack of familiarity with longer, more descriptive names, but that soon
becomes painful and even unreadable.
To a mathematician, "pi" or "π" is meaningful, and
"constant_ratio_of_diameter_to_circumference" would be much harder to read.
To a physicist, the names "E", "p", "m", "c", "e", "v", "a", etc. are all
meaningful, and while it wouldn't hurt *that* much to write them as
"energy", "momentum", "rest_mass", "speed_of_light", "charge_on_the_electron",
"velocity", "acceleration" that soon gets tedious and frankly it doesn't help
that much. If somebody doesn't understand:
p = m*v*(1-(c/v)**2)**-0.5
they aren't likely to be much enlightened by:
momentum = rest_mass*velocity*(1-(speed_of_light/velocity)**2)**-0.5
and of course, the longer names aren't likely to help the programmer find
the bug in the expression if he doesn't know the subject well.
Meaningful names are vital. But short names, even single letters, are not
necessarily less meaningful than longer, more descriptive names.
More information about the Tutor