Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #47845

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

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'compiler': 0.07; 'debugging': 0.07; 'encoded': 0.07; 'plenty': 0.07; 'suppose': 0.07; 'string': 0.09; 'oh,': 0.09; 'typed': 0.09; "'__doc__',": 0.16; "'help',": 0.16; "'set',": 0.16; 'builtins.': 0.16; 'complaints?': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inclined': 0.16; 'janssen': 0.16; 'keyword.': 0.16; 'len,': 0.16; 'overriding': 0.16; 'password,': 0.16; 'range,': 0.16; 'sees': 0.16; 'underscores,': 0.16; 'uppercase': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'variable': 0.18; 'wed,': 0.18; 'thu,': 0.19; '>>>': 0.22; 'instance,': 0.24; 'sort': 0.25; 'right.': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'work.': 0.31; 'easier': 0.31; "skip:' 10": 0.31; '13,': 0.31; '>>>>': 0.31; 'lot.': 0.31; 'retirement': 0.31; 'safely': 0.31; 'file': 0.32; "we're": 0.32; 'beginning': 0.33; "i'd": 0.34; "can't": 0.35; 'advice': 0.35; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'something': 0.35; 'editor': 0.35; 'etc': 0.35; 'good.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'should': 0.36; 'unit': 0.37; 'two': 0.37; 'list': 0.37; 'received:209': 0.37; 'area': 0.37; 'being': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; '12,': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'skip:u 10': 0.60; 'above,': 0.60; 'mentioned': 0.61; 'name:': 0.61; "you're": 0.61; "you've": 0.63; 'making': 0.63; 'name': 0.63; 'choose': 0.64; 'talking': 0.65; 'safe': 0.72; 'money': 0.72; 'further,': 0.74; 'day': 0.76; 'are...': 0.84; 'edwards': 0.91; 'subject:Don': 0.91; 'grey': 0.93; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=HHCM3kZTkavKd8e6PlnS2eUSrtId1BhQY7cysS+vgfw=; b=LsIvJaTtLFayM5smrMdYuoYAXK6eZTQ5nSbp9nakX5sDCfdoEoovHtsrXedJBJaxzR 7Apwbz0JIoTeRMHW+0UW6KQI6Xu8UrzkhOKeAJb8nS+q+atb33B0oJOBFLIxVPevCnMM cPwCMZpS5Ka36dATFDliua0ztPjotAnzsG1dAv03C+ebWHkxn9GGU+s2S7oKz44GuIQb Cz4kFKaOVbsZ77lDDFPaqN3Bqa2glHfZJju09Ib0XE+XIn3i/WLMje/noCdtICvhcdue aDUWMMXNTrDhc9s/NkXwnV5OWGol7QWhofs+6myd1hsu690I4tZHscvSWeJ9ohqcbDv8 IDyg==
MIME-Version 1.0
X-Received by 10.52.65.238 with SMTP id a14mr8764330vdt.24.1371069015176; Wed, 12 Jun 2013 13:30:15 -0700 (PDT)
In-Reply-To <CAMjeLr_ozpfk3TxaEOaenoES5jUpYnZDaYWcNbX1FctO8OLuDw@mail.gmail.com>
References <kp5q5o$fj1$1@ger.gmane.org> <mailman.3096.1371040064.3114.python-list@python.org> <kpa0ae$b4t$1@reader1.panix.com> <CAMjeLr_ozpfk3TxaEOaenoES5jUpYnZDaYWcNbX1FctO8OLuDw@mail.gmail.com>
Date Thu, 13 Jun 2013 06:30:15 +1000
Subject Re: "Don't rebind built-in names*" - it confuses readers
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3128.1371069023.3114.python-list@python.org> (permalink)
Lines 78
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1371069023 news.xs4all.nl 15883 [2001:888:2000:d::a6]:50222
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:47845

Show key headers only | View raw


On Thu, Jun 13, 2013 at 5:40 AM, Mark Janssen <dreamingforward@gmail.com> wrote:
> On Wed, Jun 12, 2013 at 7:24 AM, Grant Edwards <invalid@invalid.invalid> wrote:
>> On 2013-06-11, Mark Janssen <dreamingforward@gmail.com> wrote:
>>>>         list = []
>>>> Reading further, one sees that the function works with two lists, a list of
>>>> file names, unfortunately called 'list',
>>>
>>> That is very good advice in general:  never choose a variable name
>>> that is a keyword.
>>
>> You can't choose a vriable name that is a keyword: the compiler won't
>> allow it.
>>
>> "list" isn't a keyword.
>
> You're right.  I was being sloppy.

We're talking about builtins, and unfortunately there are... well, let
me ask Thespis, from the play of the same name:

Thespis: Oh, then I suppose there are some complaints?
Mercury: Yes, there are some.
Thespis (disturbed): Oh, perhaps there are a good many?
Mercury: There are a good many.
Thespis: Oh, perhaps there are a thundering lot?
Mercury: There are a thundering lot.
Thespis (very much disturbed): Oh.

>>> dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError',
'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError',
'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError',
'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError',
'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError',
'Exception', 'False', 'FileExistsError', 'FileNotFoundError',
'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError',
'ImportError', 'ImportWarning', 'IndentationError', 'IndexError',
'InterruptedError', 'IsADirectoryError', 'KeyError',
'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError',
'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError',
'OSError', 'OverflowError', 'PendingDeprecationWarning',
'PermissionError', 'ProcessLookupError', 'ReferenceError',
'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopIteration',
'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit',
'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError',
'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError',
'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning',
'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '_',
'__build_class__', '__debug__', '__doc__', '__import__', '__name__',
'__package__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool',
'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile',
'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod',
'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format',
'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex',
'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len',
'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min',
'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property',
'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr',
'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple',
'type', 'vars', 'zip']

I think I can safely say that all the names beginning with an
uppercase letter (exceptions, True/False/None/Ellipsis), and the ones
beginning with underscores, should not be overridden. Well and good.
Still leaves 72 builtins. Obviously overriding len, print, range, etc
would be risky (unless, as mentioned above, you're making a drop-in
replacement), but there are plenty that you'd never notice (eg if you
use "hash" for an encoded password, or "input" for the string the user
typed into an HTML form). I would hope, for instance, that an editor
would not color-highlight 'credits' differently, as it's designed for
interactive work. There are plenty in the grey area - is it safe to
use "sum" as an accumulator or "min" for a unit of time? What about
using "super" to store the amount of retirement money you've put away?
I'd be inclined to avoid this sort any time I'm aware of them, just
because it'll make debugging easier on the day when something goes
wrong.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: "Don't rebind built-in names*" - it confuses readers Mark Janssen <dreamingforward@gmail.com> - 2013-06-10 17:18 -0700
  Re: "Don't rebind built-in names*" - it confuses readers Grant Edwards <invalid@invalid.invalid> - 2013-06-12 14:24 +0000
    Re: "Don't rebind built-in names*" - it confuses readers Mark Janssen <dreamingforward@gmail.com> - 2013-06-12 12:40 -0700
    Re: "Don't rebind built-in names*" - it confuses readers Chris Angelico <rosuav@gmail.com> - 2013-06-13 06:30 +1000
    Re: "Don't rebind built-in names*" - it confuses readers Mark Janssen <dreamingforward@gmail.com> - 2013-06-12 16:07 -0700
    Re: "Don't rebind built-in names*" - it confuses readers Chris Angelico <rosuav@gmail.com> - 2013-06-13 09:53 +1000
      Re: "Don't rebind built-in names*" - it confuses readers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-13 00:47 +0000
    Re: "Don't rebind built-in names*" - it confuses readers Skip Montanaro <skip@pobox.com> - 2013-06-12 19:06 -0500
    Re: "Don't rebind built-in names*" - it confuses readers Mark Janssen <dreamingforward@gmail.com> - 2013-06-12 17:26 -0700
      Re: "Don't rebind built-in names*" - it confuses readers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-13 01:23 +0000
        Re: "Don't rebind built-in names*" - it confuses readers Nobody <nobody@nowhere.com> - 2013-06-13 11:09 +0100
    Re: "Don't rebind built-in names*" - it confuses readers Chris Angelico <rosuav@gmail.com> - 2013-06-13 10:28 +1000

csiph-web