"Don't rebind built-in names*" - it confuses readers

Terry Jan Reedy tjreedy at udel.edu
Tue Jun 11 02:06:09 EDT 2013


On 6/10/2013 10:56 PM, Steven D'Aprano wrote:

>> I was initially confused
>> and reading the code still takes a small bit of extra mental energy.
>> Idle stays confused and will wrongly color the list instance name until
>> it is changed. Calling the file list 'fnames' or 'filenames' would have
>> been clearer to both me and Idle.
>
> Correct. The downside of editors that colourise text is that sometimes
> they colourise it wrong. In this case, how is the editor supposed to know
> that list no longer refers to the built-in list?
>
> This is yet another good argument for being cautious about shadowing
> built-ins.

After posting I remembered that there are also colorized text blocks on 
web pages. Each person will have to decide for themselves whether the 
convenience of reusing a builtin name is worth having their code 
mis-colorized. As a reader, I decided that it is not.

tjr






More information about the Python-list mailing list