Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #47663
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <joshua.landau.ws@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; '"this': 0.03; 'syntax': 0.04; 'important,': 0.07; 'append': 0.09; 'builtin': 0.09; 'highlighting': 0.09; 'thus,': 0.09; 'useless': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'jan': 0.12; 'assume': 0.14; '*never*': 0.16; 'arguments:': 0.16; 'builtins': 0.16; 'editor,': 0.16; 'enough.': 0.16; 'highlight': 0.16; 'idle.': 0.16; 'long- time': 0.16; 'overwriting': 0.16; 'personally,': 0.16; 'posters': 0.16; 'rarely': 0.16; 'reedy': 0.16; 'sees': 0.16; 'str,': 0.16; 'syntax,': 0.16; 'variable.': 0.16; 'wrongly': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'obviously': 0.18; 'variable': 0.18; 'bit': 0.19; 'mechanism': 0.19; 'cc:addr:python.org': 0.22; 'example.': 0.24; 'instance,': 0.24; 'refers': 0.24; "shouldn't": 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'posts': 0.26; 'header:In-Reply- To:1': 0.27; 'function': 0.29; '----': 0.29; 'received:209.85.217': 0.29; 'change,': 0.30; 'message- id:@mail.gmail.com': 0.30; 'asked': 0.31; 'code': 0.31; 'accidentally': 0.31; 'changed.': 0.31; 'names.': 0.31; 'file': 0.32; 'open': 0.33; 'skip:_ 10': 0.34; 'problem': 0.35; 'received:209.85': 0.35; 'editor': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'are,': 0.36; 'idle': 0.36; 'method': 0.36; 'should': 0.36; 'too': 0.37; 'two': 0.37; 'list': 0.37; 'list.': 0.37; 'received:209': 0.37; 'initially': 0.38; 'list,': 0.38; 'previous': 0.38; 'that,': 0.38; 'little': 0.38; 'recent': 0.39; 'does': 0.39; 'though,': 0.39; 'enough': 0.39; 'called': 0.40; 'skip:u 10': 0.60; 'read': 0.60; 'up,': 0.60; 'worry': 0.60; 'most': 0.60; 'color': 0.61; "you're": 0.61; 'name': 0.63; 'real': 0.63; 'such': 0.63; 'happen': 0.63; 'more': 0.64; 'chance': 0.65; 'here': 0.66; 'bottom': 0.67; 'further,': 0.74; 'unusual': 0.74; 'life.': 0.83; 'clearer': 0.84; 'colored': 0.84; 'colour': 0.84; 'shadow': 0.84; 'sensibly': 0.91; 'subject:Don': 0.91; '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:from:date:message-id:subject:to :cc:content-type; bh=3wKbHnol9kAFk5mzpZF5dEr+MjxbTBlbS0teruZ3oAY=; b=ZZGD8qLVQUlkfRndiy8c+1zK6dXw+Fv4Y3h+lGN/AcH0tr/8wpKOULExfuVP4APJJ1 8IRDJpOBlvU6f/xRXXb+aXZzx5R0v9xKQfFuOX4az3Ie2p0t2wyd5urOm/N7q1kLnTI7 SvuTGMGCyOt/us3fDcq5b+kVaxYXjhEQPR6R2ZQl7abIJf1gGya5+ugcDwwnBFsQhsnG rjzqcIjVxSkCW97kPrZyF0SduEnvvJ2EuAeIwdUBFlYVMLSCEFvGtH2iv+6iBgQrofCY zIPIO3NK7DxGMICylih0gfEsXn5BAyHNieIaGftO6Oigq7l2waa+eBsZSIfl2lkp72gi 1XQA== |
| X-Received | by 10.112.5.199 with SMTP id u7mr4689911lbu.67.1370963256034; Tue, 11 Jun 2013 08:07:36 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <kp5q5o$fj1$1@ger.gmane.org> |
| References | <kp5q5o$fj1$1@ger.gmane.org> |
| From | Joshua Landau <joshua.landau.ws@gmail.com> |
| Date | Tue, 11 Jun 2013 16:06:55 +0100 |
| Subject | Re: "Don't rebind built-in names*" - it confuses readers |
| To | Terry Jan Reedy <tjreedy@udel.edu> |
| Content-Type | text/plain; charset=UTF-8 |
| Cc | python-list <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.3022.1370963265.3114.python-list@python.org> (permalink) |
| Lines | 55 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1370963265 news.xs4all.nl 15938 [2001:888:2000:d::a6]:51836 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:47663 |
Show key headers only | View raw
On 11 June 2013 01:14, Terry Jan Reedy <tjreedy@udel.edu> wrote: > Many long-time posters have advised "Don't rebind built-in names*. > > For instance, open Lib/idlelib/GrepDialog.py in an editor that colorizes > Python syntax, such as Idle's editor, jump down to the bottom and read up, > and (until it is patched) find > list.append(fn) > with 'list' colored as a builtin. Stop. That looks wrong. List.append needs > two arguments: a list instance and an object to append to the list. The > 'solution' is in a previous line > list = [] > Reading further, one sees that the function works with two lists, a list of > file names, unfortunately called 'list', and a list of subdirectories, more > sensibly call 'subdirs'. 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. The problem here is the problem with all of this - names should be descriptive. There is rarely a case where "str" or "string", even, is sufficiently detailed, and "file" often really refers to a "path" for example. You should really not worry about shadowing builtins because if you're using sufficiently long names you almost ne'er accidentally will. In one of my recent posts I was chastised by someone (I remember not who) for overwriting the "property" builtin - obviously this would *never* happen in real life. If you call your property "property" you are a fool. It means nothing! Secondly, shadowing will _almost never_ be a problem, as you invariably, given that you don't use "list" or "str" as variable names, will have shadowed a completely contextually useless variable. And thus, in the one-in-a hundred-in-a-thousand chance that you accidentally shadow a builtin that happens to be important, you can assume that your editor has a half-decent variable replacement mechanism - it's only shadowed in a single scope! ---- But enough of that, you asked about syntax highlighting. Personally, the current method is good - it reminds you when you are shadowing, but does it gently. If you're adamant that the most sensible name for your variable is "format", use it. The highlighting shouldn't be taken to mean "this is from __builtins__", but a little reminder that __builtins__ uses the name. Chances are, you won't be using "format", so do. The little colour change, though, reminds you to check that it really is the best name. Or, well, do what I do and use a proper editor, and set syntax not to highlight keywords if you care enough. My editor makes a good choice only to highlight those keywords that you really don't want to shadow - list, str, etc. - where they're just too vague to be good variable names. "Format"'s unusual and as such do what you want with it.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: "Don't rebind built-in names*" - it confuses readers Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-11 16:06 +0100
csiph-web