Strange Behavior

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Jun 3 07:44:00 EDT 2014


On Tue, 03 Jun 2014 10:01:26 +0200, Peter Otten wrote:

> Steven D'Aprano wrote:
> 
>> On Mon, 02 Jun 2014 20:05:29 +0200, robertw89 wrote:
>> 
>>> I invoked the wrong bug.py :/ , works fine now (this happens to me
>>> when im a bit tired sometimes...).
>> 
>> Clarity in naming is an excellent thing. If you have two files called
>> "bug.py", that's two too many.
> 
> In the case of the OP the code is likely to be thrown away once the bug
> is found. Putting all experiments into a single folder even with the
> overly generic name "bug" would have been "good enough" to avoid the
> problem.

Depends on how many "bugs" the OP thinks he has found. (Hint: check on 
the python bug tracker.) And of course you can't have multiple files in 
the same directory unless they have different names, so a good naming 
system is still needed.

But as you point out later:

>> Imagine having fifty files called "program.py". Which one is which? How
>> do you know? Programs should be named by what they do (think of Word,
>> which does word processing, or Photoshop, which does photo editing), or
>> when that isn't practical, at least give them a unique and memorable
>> name (Outlook, Excel). The same applies to files demonstrating bugs.
>  
> Outlook and Excel are only good names because these are popular
> applications. If I were to name some private scripts in that style and
> not use them for a few months -- I don't think I'd have a clue what
> excel.py is meant to do.

... a good naming scheme has to take into account how often you use it. 
Scripts that you *literally* throw away after use don't need to be named 
with a lot of care, just enough to keep the different versions distinct 
while you use them. More generic scripts that you keep around need a bit 
more care -- I must admit I have far too many scripts called "make_avi" 
for slightly different video-to-AVI conversion scripts. But at least 
they're not all called "script.py".

Outlook and Excel are memorable names, but if you don't use them 
frequently, you may not associate the name with the application. In the 
Python world, we have memorable names like Psyco and Pyrex, but it took 
me *ages* to remember which one was which, because I didn't use them 
often enough to remember.

(Psycho is a JIT specialising compiler, now unmaintained and obsoleted by 
PyPy; Pyrex enables you to write C extensions using Python, also 
unmaintained, and obsoleted by Cython.)

[...]
> One approach that seems to be working so far is to combine several
> scripts into one using argparse subparsers. This results in more
> frequent usage which means I can get away with short meaningless names,
[...]


Very true, but the cost is added complexity in the script.


-- 
Steven D'Aprano
http://import-that.dreamwidth.org/



More information about the Python-list mailing list