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


Groups > comp.lang.python > #47856

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

Path csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <dreamingforward@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'root': 0.05; 'debugging': 0.07; 'encoded': 0.07; 'plenty': 0.07; 'string': 0.09; 'global,': 0.09; 'seemed': 0.09; 'typed': 0.09; 'cc:addr:python-list': 0.11; 'suggest': 0.14; "'__doc__',": 0.16; "'help',": 0.16; "'set',": 0.16; 'builtins.': 0.16; 'dict': 0.16; 'inclined': 0.16; 'len,': 0.16; 'namespace,': 0.16; 'overriding': 0.16; 'password,': 0.16; 'pep8': 0.16; 'range,': 0.16; 'scope.': 0.16; 'then?': 0.16; 'tuple,': 0.16; 'underscores,': 0.16; 'uppercase': 0.16; 'obviously': 0.18; 'variable': 0.18; 'bit': 0.19; "python's": 0.19; 'seems': 0.21; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'string,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'sort': 0.25; 'right.': 0.26; 'header:In-Reply- To:1': 0.27; '(like': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'work.': 0.31; 'included': 0.31; 'easier': 0.31; "skip:' 10": 0.31; 'int,': 0.31; 'names.': 0.31; 'retirement': 0.31; 'safely': 0.31; 'beginning': 0.33; 'not.': 0.33; "i'd": 0.34; 'something': 0.35; 'editor': 0.35; 'etc': 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; 'area': 0.37; 'being': 0.38; 'skip:[ 10': 0.38; 'list,': 0.38; 'that,': 0.38; 'above,': 0.60; 'mentioned': 0.61; "you're": 0.61; "you've": 0.63; 'making': 0.63; 'such': 0.63; 'different': 0.65; 'to:addr:gmail.com': 0.65; 'safe': 0.72; 'money': 0.72; 'day': 0.76; 'subject:Don': 0.91; 'grey': 0.93; 'washington': 0.93
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 :cc:content-type; bh=/Mx3UMw4d/hkgtHgVy6oGK9TO5jPuRV1w4FANPlwVAc=; b=KMBTS5RLykJo9G4fMQS39upo8J9sN15NnrBdg2PAVTrcqJh8ohx8XhzSrAbTO8+Gl/ qMoZciIAJWRsJaJy7b2lMWpjoVclmHkSEML+PSSQ0Dv6R05N5PrbpEgPsn+NI2jTJ8z9 L36y0UaJJ41W0WSpyXliFFCKhH4krv7pvH9MhjVZDQJMka+p7MOR2BZ2sLPWbnuLaVz0 zDfYvN72Zil/7LZ1bhOziKmcDhPQoN1X8cdhgb4kRyWmWJyiduGGwSNpc/dPH6Px9QZG chXXA2UTfdQ7i9uX71/qh3jfGvD/jifuvCArBoOO42G5IQh82LiUkRdFkwfWz42xf1lL i9Jg==
MIME-Version 1.0
X-Received by 10.180.36.205 with SMTP id s13mr5974612wij.31.1371078434381; Wed, 12 Jun 2013 16:07:14 -0700 (PDT)
In-Reply-To <CAPTjJmrwx6BV=Crm9bYeayRH83OGJ48w_fy_MpB-_wHpgfimpA@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> <CAPTjJmrwx6BV=Crm9bYeayRH83OGJ48w_fy_MpB-_wHpgfimpA@mail.gmail.com>
Date Wed, 12 Jun 2013 16:07:14 -0700
Subject Re: "Don't rebind built-in names*" - it confuses readers
From Mark Janssen <dreamingforward@gmail.com>
To Chris Angelico <rosuav@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
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.3137.1371078442.3114.python-list@python.org> (permalink)
Lines 70
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1371078442 news.xs4all.nl 15925 [2001:888:2000:d::a6]:56550
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:47856

Show key headers only | View raw


>> You're right.  I was being sloppy.
>
> ['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.

Okay, now I'm a bit confused.  "print" is both a <keyword> and a
member of the builtins.  What happens then?

And abs(), max(), hex()  and such seemed like keywords to my
scientific self (due to never having to "include"/import them), but
clearly their not.  And int, list, tuple, dict and such always seemed
like keywords to my CS self because they were included in Python's
type system (like "int" would be in C).

They are all one-step removed from keywords.   And yet, since they are
not in a separate namespace, they should not be used as variable
names.  Perhaps since they are very different from one another, they
should be put in separate namespaces off of a global, root
namespace...  (math, string, etc.)

Despite that, seems like PEP8 should suggest this not shadowing these
built-ins which are at global scope.

MarkJ
Tacoma, Washington

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