Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; ';-)': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'modifying': 0.07; 'tkinter': 0.07; '"if': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'screen.': 0.09; 'will,': 0.09; 'contribute': 0.11; 'python': 0.11; 'cheers': 0.12; 'wrote': 0.14; 'language.': 0.14; '"key': 0.16; 'readability': 0.16; 'readable': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'resist': 0.16; 'spacing': 0.16; 'subject:bit': 0.16; 'tags.': 0.16; 'uh,': 0.16; 'url:file': 0.16; 'folks': 0.16; 'thursday,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'thanks.': 0.20; 'seems': 0.21; '>>>': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'affects': 0.24; "aren't": 0.24; 'satisfying': 0.24; 'url:moin': 0.24; 'fairly': 0.24; 'versions': 0.24; '---': 0.24; 'sort': 0.25; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'record': 0.27; 'appear': 0.29; '[1]': 0.29; 'points': 0.29; 'programming.': 0.30; "i'm": 0.30; 'code': 0.31; 'url:wiki': 0.31; '13,': 0.31; 'markup': 0.31; 'trivial': 0.31; 'run': 0.32; 'url:python': 0.33; 'guess': 0.33; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'google': 0.35; 'there': 0.35; 'choosing': 0.36; 'idle': 0.36; 'url:org': 0.36; 'changing': 0.37; 'too': 0.37; 'performance': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'read': 0.60; 'warm': 0.60; 'worry': 0.60; 'most': 0.60; 'free': 0.61; 'new': 0.61; 'viruses': 0.61; 'first': 0.61; 'back': 0.62; 'email addr:gmail.com': 0.63; 'protection': 0.63; 'our': 0.64; 'more': 0.64; 'taking': 0.65; 'reply': 0.66; 'antivirus': 0.68; 'useful.': 0.68; 'helping': 0.70; 'therefore': 0.72; 'special': 0.74; 'hoping': 0.75; 'glad': 0.83; '9:45': 0.84; 'batchelder': 0.84; 'flexibility,': 0.84; 'hand.': 0.84; 'improvement': 0.84; 'story:': 0.84; 'timings': 0.84; 'url:cpython': 0.84; 'step.': 0.91; 'urge': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: A curious bit of code... Date: Fri, 14 Feb 2014 21:01:48 +0000 References: <4cc09129-43ee-4205-a24c-03f92b594abc@googlegroups.com> <839842ff-e0d4-4bec-93fa-b8c25b3ca471@googlegroups.com> <6940c818-e8dc-483e-8795-9e5493050e3b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-16-159.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: <6940c818-e8dc-483e-8795-9e5493050e3b@googlegroups.com> X-Antivirus: avast! (VPS 140214-1, 14/02/2014), Outbound message X-Antivirus-Status: Clean X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 79 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392411730 news.xs4all.nl 2890 [2001:888:2000:d::a6]:42605 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66327 On 14/02/2014 20:04, forman.simon@gmail.com wrote: > On Thursday, February 13, 2014 7:26:48 PM UTC-8, Ned Batchelder wrote: >> On 2/13/14 9:45 PM, forman.simon@gmail.com wrote: >> >>> For the record I wasn't worried about the performance. ;-) >> >>> >> >>> It was for Tkinter event strings not markup tags. >> >>> >> >>> I'm glad this was the time winner! >> >>> >> >>> "key and key[0] == '<' and key[-1] == '>'" >> >>> >> >>> >> >>> Cheers to the folks who did the timings (and saved me from the trouble!) >> >>> >> >>> Last but not least... s[::len(s)-1] omg!!? ;-D >> >>> >> >> >> >> If you aren't worried about performance, why are you choosing your code >> >> based on which is the fastest? There are other characteristics >> >> (clarity, flexibility, robustness, ...) that could be more useful. > > > I guess I'm taking the word "worried" a little too seriously. > > Back story: I am hoping to contribute to IDLE and am reading the code as a first step. I came across that line of code (BTW, I was wrong: it is NOT processing Tkinter event strings but rather special " entries" in linecache.cache [1]) and had to resist the urge to change it to something more readable (to me.) But when I thought about it I wasn't able to discern if any of the new versions would actually be enough of an improvement to justify changing it. > > To be clear: I have no intention of modifying the IDLE codebase just for fairly trivial points like this one line. > > The most satisfying (to me) of the possibilities is "if key and key[0] == '<' and key[-1] == '>':" in the dimensions, if you will, of readability and, uh, unsurprising-ness, and so I was pleased to learn that that was also the fastest. > > > (FWIW, it seems to me that whoever wrote that line was influenced by shell programming. It's a shell sort of a trick to my eye.) > > > When writing Python code I *do* value "clarity, flexibility, robustness" and almost never worry about performance unless something is actually slow in a way that affects something.. > > Warm regards, > ~Simon > > > [1] http://hg.python.org/cpython/file/3a1db0d2747e/Lib/idlelib/PyShell.py#l117 > Pleased to have you on board, as I'm know that Terry Reedy et al can do with a helping hand. But please note you appear to be using google groups, hence the double line spacing above and trying to reply to paragraphs that run as a single line across the screen. Therefore would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com