Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78153
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.031 |
| X-Spam-Evidence | '*H*': 0.94; '*S*': 0.00; 'occurrences': 0.09; 'second.': 0.09; 'variables.': 0.09; 'cc:addr:python-list': 0.11; 'bug': 0.12; "'b'": 0.16; '(should': 0.16; '*why*': 0.16; '23,': 0.16; "['a',": 0.16; 'bug,': 0.16; 'comma': 0.16; 'elements,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'guessing': 0.16; 'imo,': 0.16; 'instance:': 0.16; 'integer,': 0.16; 'naming': 0.16; 'omitted.': 0.16; 'spotted': 0.16; 'visible;': 0.16; 'subject:python': 0.16; 'index': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'meant': 0.20; 'written': 0.21; 'cc:addr:python.org': 0.22; 'print': 0.22; 'visible': 0.24; 'cc:2**0': 0.24; 'compare': 0.26; 'code:': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; "doesn't": 0.30; 'forgot': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; '(maybe': 0.31; 'cells': 0.31; 'helpful.': 0.31; 'prints': 0.31; 'sep': 0.31; 'subject:some': 0.31; 'another': 0.32; 'says': 0.33; 'third': 0.33; 'comment': 0.34; 'problem': 0.35; 'info': 0.35; 'common': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'done': 0.36; 'doing': 0.36; 'thanks': 0.36; 'similar': 0.36; 'should': 0.36; 'behind': 0.37; 'wrong': 0.37; 'two': 0.37; 'list': 0.37; 'level': 0.37; 'easily': 0.37; 'others.': 0.38; 'does': 0.39; 'bad': 0.39; 'sure': 0.39; 'either': 0.39; 'how': 0.40; 'easy': 0.60; 'future': 0.60; 'is.': 0.60; 'most': 0.60; "you're": 0.61; 'first': 0.61; 'address': 0.63; 'name': 0.63; 'zip': 0.64; 'more': 0.64; 'here': 0.66; 'importantly,': 0.68; 'line,': 0.68; 'realized': 0.68; 'useful.': 0.68; 'miss': 0.74; 'obvious': 0.74; 'repeat': 0.74; 'subject:!!!': 0.74; 'subject:get': 0.81; 'comment.': 0.84; 'subject:Love': 0.91; 'to:none': 0.92; 'yourself,': 0.95; 'serious': 0.97 |
| 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=CpZeqrW2djtNMMNqcttpNgMxUlyNbrKaq6s7bRnoia8=; b=Mpr+cidB7MbC95qJ6eWXVF2BLaWtmMMUns9D11jJKSaq0+H7wvB+O1Jf9odZAUgwBG QAgO5526FX6xADPbzAKh/YGsZ7gBMYLS3Nht6fEbKOWi22hWyASsP96fOpFWkl1saVyI tP5OUy+kTl/Yf0Sp6oCnW0FxPfb/fDPrmwHZxJ+gv0ckOCX5VdVBfVqKxrO7D4yOzP3c 1Ka1o9Ck35BSoLXnBkct6L37FnQG+4VDBBW283o7Bln9YNPeem/FdG7gu5xDmSOWNeO+ mOSjKS2YvDbSBUmcDG/FI9GgHddVtyulykSCXFDwtH1yD07StT8LcIRp5Y47wi52S2P9 XffQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.20.169 with SMTP id o9mr14934125ige.14.1411397415149; Mon, 22 Sep 2014 07:50:15 -0700 (PDT) |
| In-Reply-To | <1875566412.7055487.1411396347279.JavaMail.root@sequans.com> |
| References | <CAPTjJmpwPbsrpiRkm7OLrsS-m=X3QnX_-Um0OvOxFXHtTy58eA@mail.gmail.com> <1875566412.7055487.1411396347279.JavaMail.root@sequans.com> |
| Date | Tue, 23 Sep 2014 00:50:15 +1000 |
| Subject | Re: Love to get some feedback on my first python app!!! |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <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 <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.14209.1411397424.18130.python-list@python.org> (permalink) |
| Lines | 46 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1411397424 news.xs4all.nl 2938 [2001:888:2000:d::a6]:49587 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:78153 |
Show key headers only | View raw
On Tue, Sep 23, 2014 at 12:32 AM, Jean-Michel Pichavant
<jeanmichel@sequans.com> wrote:
> For instance:
>
> cells = ['a', 'b' 'c']
> # print the first cell
> print cell[1]
>
> A bug that is easily spotted thanks to the comment. It's all about implementation versus intentions. Also note that comment should be written for the future self, and most importantly, for the current others.
I do see your point, but there's a serious problem here of code edits.
It's really easy to zip through and find all occurrences of some name
and change them - and miss the one in the comment. In this particular
case, I'm not actually sure where the bug is: is it in the first line
(should be "cell = ...") or the third ("print cells[1]")? Either way,
the comment doesn't make it any clearer, because the plural rule in
English doesn't always match naming of variables. Also, it's common in
English to count from 1, but in code to count from 0; so there's
another bug (and this might be the one you thought easily spotted) -
it should either be "cell[0]" in the third line, or "print the 1th
cell" in the second.
(Plus, there's a comma omitted. That list has two elements, but I
think it's meant to have three. However, I'm guessing that's a
transcription error, or a construction-in-email error, and nothing to
do with what you're saying.)
Now, compare this similar code:
cells = ['Chris Angelico', 'rosuav@gmail.com', 142857]
# print the email address
print(cells[2])
This says *why* it's doing what it does - what the meaning of the
index is. And it, too, has a clearly visible bug, because when it
prints out an integer, the comment makes it obvious that it's done the
wrong thing. This is, IMO, much more useful. If the code gets edited
(maybe the name used to be in two fields for First Name and Last Name,
and then someone realized how bad an idea that is - but forgot to
update the index), the original intention is visible; if it just says
"print out cell #2", it's not so helpful.
So basically, don't *purely* repeat yourself, but give some info
that's a level behind the code.
ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Love to get some feedback on my first python app!!! Chris Angelico <rosuav@gmail.com> - 2014-09-23 00:50 +1000
csiph-web