[Tutor] Lotka-Volterra Model Simulation Questions

Alan Gauld alan.gauld at btinternet.com
Sat Sep 29 23:57:09 CEST 2012

On 29/09/12 11:42, Steven D'Aprano wrote:
> On 29/09/12 19:16, Alan Gauld wrote:

>> 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,
>> 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...

> Yes, but "meaningful names" is relative to the reader,

Absolutely, see the first para above. This latter comment was explicitly 
in response to the snipped (by me) context:

"Also there are good reasons for using short names in equations. It 
makes it much easier to see the whole equation at once, which makes it 
easier to understand the equations and easier to check your code. If you 
make the variable names too long, even simple equations like these will 
have to split over several lines and be more difficult to read/check."

> To a mathematician, "pi" or "π" is meaningful, and
> "constant_ratio_of_diameter_to_circumference" would be much harder to read.

Totally agree.
My point is that we should not choose short names just to keep an 
expression on a single line. The evidence suggests that the advantages 
of longer names outweigh the advantage of a single line. But in the 
cases here where single letters evidently have expressive power in their 
own right the familiar term is preferable over a longer descriptive name.

Of course, care is needed when splitting an expression over multi lines
to keep the readability so if the terms can be naturally split by 
operator then that's the place to split them. But this is the same in 
written math too. (Most of the equations I remember reading from my 
quantum mechanics days were split over at least 3 lines... trying to 
force them into a single line would not have made them any more palatable!)

> 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

I'm slightly less convinced by that. I rarely learned Physics formulae 
by wrote  because I could usually work them out from first principles 
easily enough. So knowing what the variables represent would help me 
more than an equation of single letters if it was an equation I hadn't 
seen before. But where it is an industry standard equation using 
industry standard symbols then for sure, stick to the standard.

> 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.

Agreed, but if he knows the subject area but not the specific algorithm
it might help (again assuming standard symbology is used appropriately).

> Meaningful names are vital. But short names, even single letters, are not
> necessarily less meaningful than longer, more descriptive names.


Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list