Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32459
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <andrew3@r3dsolutions.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'output': 0.04; 'none,': 0.05; 'reject': 0.05; 'allowed.': 0.07; 'bytes.': 0.07; 'line:': 0.07; 'used.': 0.07; 'python': 0.09; '[1,': 0.09; 'bytes;': 0.09; 'considered.': 0.09; 'explanation': 0.09; 'indexes': 0.09; 'namespace': 0.09; 'path,': 0.09; 'predecessor': 0.09; 'preserve': 0.09; 'prohibits': 0.09; 'slices': 0.09; 'subclass': 0.09; 'subject:()': 0.09; 'tuple': 0.09; 'tuple.': 0.09; 'unexpected': 0.09; 'yet.': 0.13; 'library': 0.15; "hasn't": 0.15; 'clashes': 0.16; 'disallow': 0.16; 'dropping': 0.16; 'help;': 0.16; 'illustrate': 0.16; 'installs': 0.16; 'interpreter;': 0.16; "isn't.": 0.16; 'iterator,': 0.16; 'merely': 0.16; 'necessary;': 0.16; 'oct': 0.16; 'parameter,': 0.16; 'reason.': 0.16; 'redundancy': 0.16; 'simulated': 0.16; 'subject:array': 0.16; 'supported)': 0.16; 'thoughts?': 0.16; 'trivially': 0.16; 'undesirable': 0.16; 'xrange': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'bytes': 0.17; 'element': 0.17; 'integer': 0.17; '>>>': 0.18; 'code,': 0.18; 'memory': 0.18; 'code.': 0.20; 'written': 0.20; 'sort': 0.21; 'combination': 0.22; 'effort.': 0.22; 'libraries': 0.22; 'url:02': 0.22; 'sets': 0.23; 'installed': 0.23; 'allows': 0.25; 'least': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'fit': 0.26; 'values': 0.26; 'supported': 0.26; 'embedded': 0.27; 'possibly': 0.27; 'andrew': 0.27; 'developing': 0.28; 'fixed': 0.28; 'actual': 0.28; 'run': 0.28; 'post': 0.28; '-0700,': 0.29; '20%': 0.29; '>>>>': 0.29; 'about.': 0.29; "d'aprano": 0.29; 'installed,': 0.29; 'issues.': 0.29; 'steven': 0.29; 'url:2008': 0.29; 'no,': 0.29; 'objects': 0.29; 'skip:_ 10': 0.29; 'probably': 0.29; 'class': 0.29; 'notes': 0.30; 'lists': 0.31; 'code': 0.31; 'point': 0.31; 'could': 0.32; 'print': 0.32; 'anywhere': 0.33; 'certain': 0.33; 'curious': 0.33; 'legacy': 0.33; 'to:addr:python- list': 0.33; 'typically': 0.33; 'version': 0.34; "can't": 0.34; 'list': 0.35; 'clear': 0.35; 'pm,': 0.35; 'sometimes': 0.35; 'there': 0.35; 'list.': 0.35; 'really': 0.36; 'but': 0.36; 'url:org': 0.36; 'alone': 0.36; 'method': 0.36; 'useful': 0.36; 'too': 0.36; 'problems': 0.36; 'enough': 0.36; 'possible': 0.37; 'optimization': 0.37; 'more': 0.63; 'show': 0.63; 'subject.': 0.65; 'useful.': 0.65; 'finally': 0.66; 'talking': 0.66; 'header :Reply-To:1': 0.68; 'behaviors': 0.71; 'reply-to:no real name:2**0': 0.72; 'discover': 0.72; 'special': 0.73; 'savings': 0.75; 'dismissed': 0.84; 'everything.': 0.84; 'experiment': 0.84; 'footprint': 0.84; 'implications': 0.84; 'perspective,': 0.84; 'taken.': 0.84; 'yielded': 0.84; 'behaviors.': 0.91; 'received:173.201': 0.91; 'url:23': 0.93 |
| Date | Mon, 29 Oct 2012 12:34:24 -0700 |
| From | Andrew Robinson <andrew3@r3dsolutions.com> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111126 Thunderbird/8.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Negative array indicies and slice() |
| References | <6998a955-7b34-4f4f-b8d6-62d1028f7561@googlegroups.com> <mailman.2986.1351482209.27098.python-list@python.org> <4c024364-84df-403b-8b9e-4a4c8f06121c@googlegroups.com> <mailman.2991.1351484760.27098.python-list@python.org> <cd108b9d-e951-463e-8e50-a5a024a27c7f@googlegroups.com> <508e6649$0$29967$c3e8da3$5496439d@news.astraweb.com> <508E1BC9.3000308@r3dsolutions.com> <CALwzid=rhea2aMXM_St2FwTiAx+cnZ20_H6RtwW0_81uSQAFBQ@mail.gmail.com> <mailman.3053.1351550917.27098.python-list@python.org> <508f1910$0$29967$c3e8da3$5496439d@news.astraweb.com> |
| In-Reply-To | <508f1910$0$29967$c3e8da3$5496439d@news.astraweb.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | andrew3@r3dsolutions.com |
| 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.3067.1351564823.27098.python-list@python.org> (permalink) |
| Lines | 108 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1351564823 news.xs4all.nl 6939 [2001:888:2000:d::a6]:55984 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:32459 |
Show key headers only | View raw
On 10/29/2012 05:02 PM, Steven D'Aprano wrote: > On Mon, 29 Oct 2012 08:42:39 -0700, Andrew Robinson wrote: > >>>> But, why can't I just overload the existing __getitem__ for lists and >>>> not bother writing an entire class? > You say that as if writing "an entire class" was a big complicated > effort. It isn't. It is trivially simple, a single line: > > class MyList(list): > ... No, I don't think it big and complicated. I do think it has timing implications which are undesirable because of how *much* slices are used. In an embedded target -- I have to optimize; and I will have to reject certain parts of Python to make it fit and run fast enough to be useful. >>> You can just overload that one method in a subclass of list. Being >>> able to monkey-patch __getitem__ for the list class itself would not be >>> advisable, as it would affect all list slicing anywhere in your program >>> and possibly lead to some unexpected behaviors. >> That's what I am curious about. >> What unexpected behaviors would a "monkey patch" typically cause? > What part of "unexpected" is unclear? > Ahh -- The I don't know approach! It's only unexpected if one is a bad programmer...! > Let me see if I can illustrate a flavour of the sort of things that can > happen if monkey-patching built-ins were allowed. > > You create a list and print it: > > # simulated output > py> x = [5, 2, 4, 1] > py> print(x) > [1, 2, 4, 5] <snip> Finally you search deep into the libraries used in your code, and *five days later* discover that your code uses library A which uses library B which uses library C which uses library D which installs a harmless monkey-patch to print, but only if library E is installed, and you just happen to have E installed even though your code never uses it, AND that monkey-patch clashes with a harmless monkey-patch to list.__getitem__ installed by library F. And even though each monkey-patch alone is harmless, the combination breaks your code's output. Right, which means that people developing the libraries made contradictory assumptions. > Python allows, but does not encourage, monkey-patching of code written in > pure Python, because it sometimes can be useful. It flat out prohibits > monkey-patching of builtins, because it is just too dangerous. > > Ruby allows monkey-patching of everything. And the result was predictable: > > http://devblog.avdi.org/2008/02/23/why-monkeypatching-is-destroying-ruby/ > I read that post carefully; and the author purposely notes that he is exaggerating. BUT Your point is still well taken. What you are talking about is namespace preservation; and I am thinking about it. I can preserve it -- but only if I disallow true Python primitives in my own interpreter; I can't provide two sets in the memory footprint I am using. From my perspective, the version of Python that I compile will not be supported by the normal python help; The predecessor which first forged this path, Pymite, has the same problems -- however, the benefits ought-weigh the disadvantages; and the experiment yielded useful information on what is redundant in Python (eg: range is not supported) and when that redundancy is important for some reason. If someone had a clear explanation of the disadvantages of allowing an iterator, or a tuple -- in place of a slice() -- I would have no qualms dropping the subject. However, I am not finding that yet. I am finding very small optimization issues... The size of an object is at least 8 bytes. Hence, three numbers is going to be at least 24 bytes; and that's 24 bytes in *excess* of the size of slice() or tuple () which are merely containers. So -- There *ARE* savings in memory when using slice(), but it isn't really 2x memory -- its more like 20% -- once the actual objects are considered. The actual *need* for a slice() object still hasn't been demonsrated. I am thinking that the implementation of __getitem__() is very poor probably because of legacy issues. A tuple can also hold None, so ( 1, None, 2 ) is still a valid Tuple. Alternately: An iterator, like xrange(), could be made which takes None as a parameter, or a special value like 'inf'. Since these two values would never be passed to xrange by already developed code, allowing them would not break working code. I am only aware of one possible reason that slice() was once thought to be necessary; and that is because accessing the element of a tuple would recursively call __getitem__ on the tuple. But, even that is easily dismissed once the fixed integer indexes are considered. Your thoughts? Do you have any show stopper insights?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Negative array indicies and slice() andrewr3mail@gmail.com - 2012-10-28 20:12 -0700
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-28 21:42 -0600
Re: Negative array indicies and slice() andrewr3mail@gmail.com - 2012-10-28 21:00 -0700
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-28 22:25 -0600
Re: Negative array indicies and slice() Andrew <andrewr3mail@gmail.com> - 2012-10-29 00:54 -0700
Re: Negative array indicies and slice() Chris Rebert <clp2@rebertia.com> - 2012-10-29 01:18 -0700
Re: Negative array indicies and slice() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-29 11:19 +0000
Re: Negative array indicies and slice() Chris Angelico <rosuav@gmail.com> - 2012-10-29 22:32 +1100
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-10-28 21:52 -0700
Re: Negative array indicies and slice() Chris Angelico <rosuav@gmail.com> - 2012-10-29 23:40 +1100
Re: Negative array indicies and slice() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-29 22:02 +0000
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-10-28 23:01 -0700
Re: Negative array indicies and slice() Roy Smith <roy@panix.com> - 2012-10-29 09:52 -0400
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-10-29 08:20 -0700
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-29 17:01 -0600
Re: Negative array indicies and slice() Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-10-30 00:04 +0000
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-10-29 16:54 -0700
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-30 02:15 -0600
Re: Negative array indicies and slice() Chris Angelico <rosuav@gmail.com> - 2012-10-30 00:53 +1100
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-29 11:09 -0600
Re: Negative array indicies and slice() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-29 22:14 +0000
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-10-29 08:42 -0700
Re: Negative array indicies and slice() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-30 00:02 +0000
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-10-29 12:34 -0700
Re: Negative array indicies and slice() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-30 08:17 +0000
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-10-30 08:47 -0700
Re: Negative array indicies and slice() Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-30 23:48 +0000
Re: Negative array indicies and slice() Michael Torrie <torriem@gmail.com> - 2012-10-30 23:29 -0600
Re: Negative array indicies and slice() Michael Torrie <torriem@gmail.com> - 2012-10-29 23:53 -0600
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-10-29 17:04 -0700
Re: Negative array indicies and slice() Chris Angelico <rosuav@gmail.com> - 2012-10-30 09:55 +1100
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-29 17:07 -0600
Re: Negative array indicies and slice() Roy Smith <roy@panix.com> - 2012-10-29 19:24 -0400
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-29 17:43 -0600
Re: Negative array indicies and slice() Roy Smith <roy@panix.com> - 2012-10-29 20:17 -0400
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-29 18:05 -0600
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-10-29 11:00 -0700
Re: Negative array indicies and slice() Chris Kaynor <ckaynor@zindagigames.com> - 2012-10-29 18:49 -0700
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-10-29 15:39 -0700
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-29 23:55 -0600
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-30 00:51 -0600
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-10-29 17:17 -0700
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-30 01:21 -0600
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-30 01:32 -0600
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-30 02:46 -0600
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-30 12:02 -0600
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-10-30 07:21 -0700
Re: Negative array indicies and slice() Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-30 21:33 +0000
Re: Negative array indicies and slice() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-31 10:07 +0000
Re: Negative array indicies and slice() Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-31 16:01 +0000
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-30 15:47 -0600
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-30 15:55 -0600
Re: Negative array indicies and slice() Chris Angelico <rosuav@gmail.com> - 2012-10-31 09:00 +1100
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-30 16:02 -0600
Re: Negative array indicies and slice() Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-30 23:30 +0000
Re: Negative array indicies and slice() Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-29 11:27 -0600
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-10-29 16:33 -0700
Re: Negative array indicies and slice() Andrew <andrewr3mail@gmail.com> - 2012-10-29 00:54 -0700
Re: Negative array indicies and slice() andrewr3mail@gmail.com - 2012-10-28 21:00 -0700
Re: Negative array indicies and slice() Andrew <andrewr3mail@gmail.com> - 2012-10-28 21:09 -0700
Re: Negative array indicies and slice() alex23 <wuwei23@gmail.com> - 2012-10-28 21:44 -0700
Re: Negative array indicies and slice() andrewr3mail@gmail.com - 2012-10-29 01:24 -0700
Re: Negative array indicies and slice() Chris Rebert <clp2@rebertia.com> - 2012-10-29 01:37 -0700
Re: Negative array indicies and slice() andrewr3mail@gmail.com - 2012-10-29 01:59 -0700
Re: Negative array indicies and slice() Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-29 09:36 +0000
Re: Negative array indicies and slice() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-29 10:34 +0000
Re: Negative array indicies and slice() andrewr3mail@gmail.com - 2012-10-29 01:59 -0700
Re: Negative array indicies and slice() Paul Rubin <no.email@nospam.invalid> - 2012-10-28 22:14 -0700
Re: Negative array indicies and slice() andrewr3mail@gmail.com - 2012-10-29 01:08 -0700
Re: Negative array indicies and slice() Chris Rebert <clp2@rebertia.com> - 2012-10-29 01:26 -0700
Re: Negative array indicies and slice() Andrew <andrewr3mail@gmail.com> - 2012-10-28 21:09 -0700
Re: Negative array indicies and slice() MRAB <python@mrabarnett.plus.com> - 2012-10-29 03:45 +0000
Re: Negative array indicies and slice() 88888 Dihedral <dihedral88888@googlemail.com> - 2012-11-01 18:08 -0700
csiph-web