Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86500
| References | <mailman.19215.1424897186.18130.python-list@python.org> <54ef1bb8$0$2175$65785112@news.neostrada.pl> |
|---|---|
| Date | 2015-02-27 00:37 +1100 |
| Subject | Re: Python Worst Practices |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.19256.1424957869.18130.python-list@python.org> (permalink) |
On Fri, Feb 27, 2015 at 12:12 AM, m <mvoicem@gmail.com> 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?
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Python Worst Practices Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-25 20:45 +0000
Re: Python Worst Practices Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-26 10:54 +1100
Re: Python Worst Practices Chris Angelico <rosuav@gmail.com> - 2015-02-26 11:26 +1100
Re: Python Worst Practices Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-26 23:26 +1100
Re: Python Worst Practices Chris Angelico <rosuav@gmail.com> - 2015-02-27 00:12 +1100
Re: Python Worst Practices wxjmfauth@gmail.com - 2015-02-25 22:46 -0800
Re: Python Worst Practices m <mvoicem@gmail.com> - 2015-02-26 14:12 +0100
Re: Python Worst Practices Chris Angelico <rosuav@gmail.com> - 2015-02-27 00:37 +1100
csiph-web