Namespaces: memory vs 'pollution'

DL Neil PythonList at DancesWithMice.info
Mon Jul 22 23:12:30 EDT 2019


On 22/07/19 9:40 PM, Thomas Jollans wrote:
> On 22/07/2019 07.06, DL Neil wrote:
>>
>> Current thoughts:
>>
>>      import environment_module as em
>>
>> - so, even more of an abbreviation than suggested!?
>> - I rarely need to write a long list of import statements, so there
>> won't be many.
>> - not normally using such abbreviations in my code, they will stand-out.
>> - considered using upper-case, eg "EM" - it is a form of constant
>> after-all
> 
> 
> Just FYI, in the scientific Python community certain short abbreviations
> are the norm. Many modules have a ‘standard’ abbreviation that most
> people use, minimizing confusion.
> 
> import numpy as np
> import matplotlib as mpl
> from matplotlib import pyplot as plt
> import pandas as pd
> import xarray as xr
> 
> and so on.
> 
> As long as you're consistent and use the same abbreviation across your
> entire codebase, and you put the imports at the top where people can
> find them, I think using 2–4 letter abbreviations, even without any
> decoration, is a fine approach.


+1
Thanks for this.

Wow, but my little/personal utilities are far from such 'exalted' company!

The important provision is that 'everyone' (affected) understands. As 
long as we all come from the same subject-domain, eg statisticians, then 
there's no problem with 'breaking the rules' because such abbreviations 
are easily-understood 'symbols', by definition.

After all, PEP-8 does say: "names ... [should] reflect usage"!

However, I'd never concede that to a group of 'commerce' trainees, for 
example!

The use of meaningful names is a minimum professional standard (IMHO), 
and in my experience, a virtue that pays for itself. I am ever-so 
grateful that most modern text-editors will guess/read-my-mind and save 
the typing!

-- 
Regards =dn



More information about the Python-list mailing list