Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'subject:Python': 0.06; 'list?': 0.07; 'variables': 0.07; 'lawrence': 0.09; 'msg': 0.09; 'variables.': 0.09; 'yeah,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; '16.': 0.16; 'advocating': 0.16; 'bond': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'java.': 0.16; 'lower-case': 0.16; 'variables,': 0.16; 'index': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'feb': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'integer': 0.24; "shouldn't": 0.24; 'java': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'on,': 0.29; '[1]': 0.29; 'am,': 0.29; 'character': 0.29; 'topic': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'long.': 0.31; 'supposed': 0.32; 'fri,': 0.33; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'dates': 0.36; 'should': 0.36; 'detail': 0.37; 'wrong': 0.37; 'short': 0.38; 'anything': 0.39; 'how': 0.40; "you're": 0.61; 'back': 0.62; 'name': 0.63; 'great': 0.65; 'between': 0.67; 'bothered': 0.68; 'obvious': 0.74; '2015': 0.84; 'ridiculously': 0.84; 'short,': 0.84; 'subject:Practices': 0.84; 'to:none': 0.92 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:cc :content-type; bh=6jjccJ0bSJG2V/8jz6BXsU3Ngjrm5vkOIrzZexSyXVI=; b=H+3wHFiV+3oPULM6Ty1/m9VmJsxf/tO4tMD4KCNxuVWk5CqmhKoHd2VhDJznsh8Sro dlmQFLnkP8vd5Cc7rb2VbYK7DQ4mXXPUWA6SqNwD7cryesk8CjvLgToiOrWkLMUWuzhn KHLpTnDFKnzVPiknS3L+ZeoqPl7fUXCCHo9EkSVQud28PQBfIOf8flzecanimZ8eoHGS lzYQ/sWsEiRC25iFfedrFumdlen3kGZ+T+kCmByH63EkUwVoxjBWU1P/6hLGM1+qjMwP qjaQoVMIG0FUE+p5WoBqdtyYFoCjDdT4zlazx22pI1JVvd6FHDCC0d540T+iLrxFciBo HxFg== MIME-Version: 1.0 X-Received: by 10.50.114.4 with SMTP id jc4mr34026860igb.14.1424957860079; Thu, 26 Feb 2015 05:37:40 -0800 (PST) In-Reply-To: <54ef1bb8$0$2175$65785112@news.neostrada.pl> References: <54ef1bb8$0$2175$65785112@news.neostrada.pl> Date: Fri, 27 Feb 2015 00:37:39 +1100 Subject: Re: Python Worst Practices From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424957869 news.xs4all.nl 2946 [2001:888:2000:d::a6]:57789 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86500 On Fri, Feb 27, 2015 at 12:12 AM, m wrote: > W dniu 25.02.2015 21:45, Mark Lawrence pisze: >> >> http://www.slideshare.net/pydanny/python-worst-practices >> >> Any that should be added to this list? Any that be removed as not that >> bad? >> > > > I disagree with slide 16. If I wanted to use long variable names, I would > still code in Java. Clearly you aren't bothered by ambiguities, given that your name is "m". You're lower-case m, and the James Bond character is upper-case M... yeah, this isn't going to be a problem, with seven billion people on the planet! In case it's not obvious from slide 17, the author is advocating neither the ridiculously short, nor the ridiculously long. This is a topic that you could go into great detail on, but a general rule of thumb is that short names go with short-lived variables, and longer names go with large-scope variables. [1] So your function names shouldn't be single letters, but your loop counters can and should be short: def discard_all_spam(): for msg in self.messages: if msg.is_spam(): ms.discard() And of course, the use of "i" as an integer loop index dates back so far and is so well known that you don't need anything else: def get_password(): for i in range(4): if i: print("%d wrong tries...") s = input("What's the password? ") if validate_password(s): return s print("Too many wrong tries, go away.") This isn't Java coding. ChrisA [1] Yes, Python doesn't have variables per se. But how else am I supposed to differentiate between the name and the concept of a name binding?