Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Nature, to be commanded, must be obeyed. -- Francis Bacon


devel / comp.lang.python / Re: =- and -= snag

SubjectAuthor
o Re: =- and -= snagChris Angelico

1
Re: =- and -= snag

<mailman.2293.1678756052.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22390&group=comp.lang.python#22390

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: =- and -= snag
Date: Tue, 14 Mar 2023 12:07:19 +1100
Lines: 62
Message-ID: <mailman.2293.1678756052.20444.python-list@python.org>
References: <CAEtLV=oHw_VEWd2WEqtD2Xv+Yp0WYeOh_3YgNvfG8ZW69UmXqg@mail.gmail.com>
<7bc3eb74-622f-392f-b400-5e99cc7b0d29@digipen.edu>
<CAPTjJmrmECUJy-tMMhNumENjM9Q3stdaf3RMD0=9G2dpwN0CGg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de xch1SdsuiJ1WweWHdala1wmZ44UaURAdvVKDieEKcYxQ==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=Akuan2AR;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.027
X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; '2023': 0.07; 'mar': 0.07;
'moment,': 0.07; 'programmer': 0.07; 'that?': 0.07; 'flags': 0.09;
"shouldn't": 0.09; 'problem.': 0.15; '2:26': 0.16; 'calculations':
0.16; 'chrisa': 0.16; 'clues': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'spot': 0.16; 'turns': 0.16;
'whitespace,': 0.16; 'wrote:': 0.16; 'python': 0.16; 'instead':
0.17; "aren't": 0.19; 'pm,': 0.19; 'tue,': 0.19; 'to:addr:python-
list': 0.20; 'code': 0.23; 'space': 0.26; 'binary': 0.26; "isn't":
0.27; 'error': 0.29; 'putting': 0.31; 'program': 0.31; '(this':
0.32; 'gary': 0.32; 'negative': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'but': 0.32; 'there': 0.33; 'able':
0.34; 'same': 0.34; "didn't": 0.34; 'mean': 0.34; 'header:In-
Reply-To:1': 0.34; 'received:google.com': 0.34; 'definitely':
0.35; 'from:addr:gmail.com': 0.35; 'count': 0.36; "it's": 0.37;
'received:209.85': 0.37; 'way': 0.38; 'error,': 0.38;
'received:209': 0.39; 'received:209.85.208': 0.39; 'use': 0.39;
'exact': 0.40; 'something': 0.40; 'including': 0.60; "there's":
0.61; 'lower': 0.62; 'today,': 0.62; 'email addr:gmail.com': 0.63;
'simply': 0.63; 'thus': 0.64; 'your': 0.64; 'parts': 0.65; 'look':
0.65; 'let': 0.66; 'numbers': 0.67; 'right': 0.68; 'attention':
0.71; 'chance': 0.71; 'head': 0.73; 'extra': 0.84; 'thus:': 0.84;
'violates': 0.84; 'positions.': 0.91; 'guides': 0.96
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20210112; t=1678756051;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=Bk9hG8/yt1pI6PK2XnwTTBpqPviuQDkGGf+f19al+cA=;
b=Akuan2ARsnFCQGH6EXgzfp/8I1OOFZ05WhMyKzJyuk3augIMXlE6iKY6Ge+bAn6zEF
VDmEA3aygyJGKj7TUyyOdZXwy7KjCV4r78oePNTaGPKH3cB02Wl6dP+wbi3ZA3FLWmUL
evqCWbzGCBzb6C+t58ngAGMIUHckHqNrSRHI4FFdSnJljNTcjEjwQIa6eEi6TrB9HzGc
KPdNeWEFJY8lU0Gd7Z9C+v4aVf4zXYnZFT+e8eBRNiVrVJHJTBfiKHS8TB0nh4pd13qS
H/Hixkxk4GT3MImWPY1o71uLuyu4V6+uBRzD0lrLK+t8EqP7zUhJBXmgZzRCIOhWxR+0
UH6Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112; t=1678756051;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=Bk9hG8/yt1pI6PK2XnwTTBpqPviuQDkGGf+f19al+cA=;
b=ObqN258c++TfOCa8Oh6Eu1xojgnH3zWwGszC5PxvkYaR0MubrY+cOOIp1+eCZhnJUb
zXe4C8wzj4f2H31R68QeMtm4HiNkVvoxQvFIeb5KdSugFyQaJqW9nsHGn0c3eQYOa+ld
2PnEFyYkDIWGLEg7jVe55XwDyQwswbAvn9AgxROAtW08YQzsSrBHDUzkOO2pH5nQQPg/
IQ85YUgBRvvEWNpXq+mDdKH6t5YmbIaBkAQ6P/PMpKtfgErF0/lp6RR2nUmiY80TrO3W
s7A8tYtR4JCqL44VdRa7RuHJRb08P8sQVr1ZkoZgMeta9f+n/xJMv6t3iO4HGCxtHbC9
O5oQ==
X-Gm-Message-State: AO0yUKXl/AtWv2G2v5Z6YzCNW7aSCPfXRJ4Xx3CAtZtnLUUeVXFH/AY5
gA2nh2udePhsIjOsnsUazS7wayjar/+G/0+uHasGWbNWigA=
X-Google-Smtp-Source: AK7set+q7sjbhqH3/L6lN+2vw3Dgo47Z7guCCwEtR66V562yFNiiBC3JkoCUswrswQnTrUy/8eF0c7uHPTczKdp7vac=
X-Received: by 2002:a17:906:a449:b0:8eb:27de:447c with SMTP id
cb9-20020a170906a44900b008eb27de447cmr249069ejb.13.1678756050793; Mon, 13 Mar
2023 18:07:30 -0700 (PDT)
In-Reply-To: <7bc3eb74-622f-392f-b400-5e99cc7b0d29@digipen.edu>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <CAPTjJmrmECUJy-tMMhNumENjM9Q3stdaf3RMD0=9G2dpwN0CGg@mail.gmail.com>
X-Mailman-Original-References: <CAEtLV=oHw_VEWd2WEqtD2Xv+Yp0WYeOh_3YgNvfG8ZW69UmXqg@mail.gmail.com>
<7bc3eb74-622f-392f-b400-5e99cc7b0d29@digipen.edu>
 by: Chris Angelico - Tue, 14 Mar 2023 01:07 UTC

On Tue, 14 Mar 2023 at 11:37, Gary Herron <gherron@digipen.edu> wrote:
>
>
> On 3/13/23 2:26 PM, morphex@gmail.com wrote:
> > Hi.
> >
> > I was working in Python today, and sat there scratching my head as the
> > numbers for calculations didn't add up. It went into negative numbers,
> > when that shouldn't have been possible.
> >
> > Turns out I had a very small typo, I had =- instead of -=.
> >
> > Isn't it unpythonic to be able to make a mistake like that?
> >
> > Regards,
> >
> > Morten
> >
>
> These all mean the same thing, but I don't see a good way to designate
> the second or third as an error.
>
>
> x = -5
> x=-5
> x =- 5
>

The second one isn't definitely an error, but the third is a failure
of style. Many style guides mandate, for instance, equal whitespace
either side of a binary operator. It's pretty straight-forward for a
program to tokenize your code the exact same way that Python would, so
it will interpret it thus:

NAME "x"
(whitespace " ")
OP "="
OP "-"
(whitespace " ")
NUMBER "5"

The whitespace parts aren't tokens in the normal sense, but worst
case, you can count positions. And since there's one space prior to
the "=" and none after, it violates the style rule, and can thus be
flagged.

(This is one reason that I detest autoformatters. You might notice the
autoformatter relayout your code into "x = -5", but if you don't spot
it right at that moment, there's a lower chance that it'll look like a
problem. OTOH, something that simply flags the error and leaves it for
you to fix, even if you don't notice it immediately, will bring this
line to your attention and let you wonder whether it's misformatted or
miscoded.)

Of course, all this is predicated on you actually putting whitespace
around your equals signs. If you write it all crunched together as
"x=-5", there's no extra clues to work with.

Linters and code reviewers can make use of all the available
information, including whitespace, to determine programmer intent.

ChrisA

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor