Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90284
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.014 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'assignment': 0.07; 'attribute': 0.07; 'modify': 0.07; 'odd': 0.07; 'caller': 0.09; 'explanation': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wrote': 0.14; 'declaration': 0.16; 'dict': 0.16; 'reasonably': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'tuple': 0.16; 'typeerror:': 0.16; 'all.': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'trying': 0.19; 'instead.': 0.24; 'academic': 0.26; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'testing': 0.29; 'code': 0.31; "skip:' 10": 0.31; '"",': 0.31; 'overhead': 0.31; 'file': 0.32; '(most': 0.33; 'becomes': 0.33; 'comment': 0.34; 'problem': 0.35; 'beyond': 0.35; 'but': 0.35; 'there': 0.35; 'introducing': 0.36; 'subject:?': 0.36; 'should': 0.36; 'list': 0.37; 'starting': 0.37; 'step': 0.37; 'to:addr:python-list': 0.38; 'anything': 0.39; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'read': 0.60; 'problems.': 0.60; 'gone': 0.61; 'new': 0.61; 'simply': 0.61; 'simple': 0.61; "you're": 0.61; 'show': 0.63; 'real': 0.63; 'became': 0.64; 'become': 0.64; 'more': 0.64; 'situation': 0.65; 'frank': 0.68; 'reads': 0.68; 'real-world': 0.68; 'safe': 0.72; 'subject:this': 0.83; 'exercise,': 0.84; 'premise': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | "Frank Millman" <frank@chagford.com> |
| Subject | Re: Is this unpythonic? |
| Date | Sun, 10 May 2015 12:40:47 +0200 |
| References | <mailman.224.1431072121.12865.python-list@python.org> <554c8b0a$0$12992$c3e8da3$5496439d@news.astraweb.com> <mii4il$vv$1@ger.gmane.org> <mailman.239.1431086688.12865.python-list@python.org> <min3f0$2gh$1@news.albasani.net> <mailman.302.1431248365.12865.python-list@python.org> <min9t3$e56$1@news.albasani.net> |
| X-Gmane-NNTP-Posting-Host | 197.89.67.74 |
| X-MSMail-Priority | Normal |
| X-Newsreader | Microsoft Outlook Express 6.00.3790.4657 |
| X-RFC2646 | Format=Flowed; Original |
| X-MimeOLE | Produced By Microsoft MimeOLE V6.00.3790.4913 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.306.1431256992.12865.python-list@python.org> (permalink) |
| Lines | 58 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1431256992 news.xs4all.nl 2936 [2001:888:2000:d::a6]:59450 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:90284 |
Show key headers only | View raw
"Johannes Bauer" <dfnsonfsduifb@gmx.de> wrote in message news:min9t3$e56$1@news.albasani.net... On 10.05.2015 10:58, Frank Millman wrote: > > It is then a simple extra step to say - > > > > EMPTY_L:IST = () > > > > and if required - > > > > EMPTY_DICT = () > > > > and expand the explanation to show why a tuple is used instead. > > > > So if there was a situation where the overhead of testing for None > > became a > > problem, this solution offers the following - > > > > 1. it solves the 'overhead' problem > > 2. it reads reasonably intuitively in the body of the program > > 3. it is safe > > 4. it should not be difficult to write a suitable self-explanatory > > comment > I do understand what you're trying to do, but it is my gut-feeling that > you're overengineering this and as a side-effect introducing new problems. This has actually gone beyond a practical suggestion, and become more of an academic exercise, so I don't think 'overengineering' comes into it. No-one is recommending that this should be used in real-world code. > With the above declaration as you describe, the code becomes weird: > > foo = EMPTY_LIST > foo.append(123) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > AttributeError: 'tuple' object has no attribute 'append' > > and > > foo = EMPTY_DICT > foo["bar"] = "moo" > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: 'tuple' object does not support item assignment The whole point of this admittedly odd declaration is that no-one should do anything with it at all. It is simply a place-holder to be used in the absence of a real list or dict provided by the caller of the function. The starting premise was that the function would only read from the list/dict, not try to modify it. Frank
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-08 10:01 +0200
Re: Is this unpythonic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-08 20:08 +1000
Re: Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-08 12:53 +0200
Re: Is this unpythonic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-09 01:07 +1000
Re: Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-09 07:56 +0200
Re: Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-09 08:51 +0200
Re: Is this unpythonic? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-05-09 19:47 +1200
Re: Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-09 11:10 +0200
Re: Is this unpythonic? Dave Angel <davea@davea.name> - 2015-05-08 08:04 -0400
Re: Is this unpythonic? Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-05-10 10:04 +0200
Re: Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-10 10:58 +0200
Re: Is this unpythonic? Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-05-10 11:54 +0200
Re: Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-10 12:40 +0200
Re: Is this unpythonic? "Frank Millman" <frank@chagford.com> - 2015-05-08 15:12 +0200
csiph-web