Deutsch   English   Français   Italiano  
<mailman.86.1730885766.4695.python-list@python.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: Roel Schroeven <roel@roelschroeven.net>
Newsgroups: comp.lang.python
Subject: Re: Two python issues
Date: Wed, 6 Nov 2024 10:36:01 +0100
Lines: 64
Message-ID: <mailman.86.1730885766.4695.python-list@python.org>
References: <700403c2-e052-4670-b2ec-eaf9b4babada@pandora.be>
 <0779f355-ed05-43cb-aa05-1afded82246c@roelschroeven.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de BYRkzG5HuNTkj28UVZd3xwXbM6jJU5CaDso0BaeX4agA==
Cancel-Lock: sha1:RdolpqIzw89EdtuG2jgYNqQdr3s= sha256:jLAYi3V9f9Ys2SKCBp/CdkME4dN4mu7R5KEIsHhWcP4=
Return-Path: <roel@roelschroeven.net>
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=roelschroeven.net header.i=@roelschroeven.net
 header.b=KTsTsKy/; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.118
X-Spam-Level: *
X-Spam-Evidence: '*H*': 0.76; '*S*': 0.00; 'traceback': 0.04; '(most':
 0.05; 'bigger': 0.05; 'last):': 0.05; 'example:': 0.09;
 'options,': 0.09; 'theoretical': 0.09; 'valueerror:': 0.09;
 'subject:python': 0.10; '(b)': 0.16; 'far,': 0.16; 'forever.':
 0.16; 'found,': 0.16; 'indeed': 0.16; 'languages.': 0.16;
 'received:10.202': 0.16; 'received:10.202.2': 0.16;
 'received:internal': 0.16; 'received:messagingengine.com': 0.16;
 'schreef': 0.16; 'strings,': 0.16; 'python': 0.16; 'instead':
 0.17; 'probably': 0.17; 'subject:issues': 0.19; 'to:addr:python-
 list': 0.20; 'languages': 0.22; 'exception': 0.22; 'code': 0.23;
 'idea': 0.24; 'anything': 0.25; 'programming': 0.25; '>>>': 0.28;
 'wrong': 0.28; 'think': 0.29; 'error': 0.29; 'header:User-
 Agent:1': 0.30; 'seem': 0.31; '"",': 0.32; 'concept': 0.32;
 'elements': 0.32; 'language.': 0.32; 'negative': 0.32;
 'returning': 0.32; 'but': 0.32; "i'm": 0.33; 'there': 0.33;
 'header:In-Reply-To:1': 0.34; 'able': 0.34; 'same': 0.34; 'mean':
 0.34; 'trying': 0.35; 'complex': 0.35; 'item': 0.35; 'those':
 0.36; 'lists': 0.37; 'necessarily': 0.37; 'currently': 0.37;
 'using': 0.37; "it's": 0.37; 'others': 0.37; 'though': 0.37;
 'file': 0.38; 'list': 0.39; 'use': 0.39; 'two': 0.39; "that's":
 0.39; 'changes': 0.39; 'otherwise': 0.39; 'valid': 0.39;
 'consistent': 0.40; 'hand': 0.40; 'match': 0.40; 'something':
 0.40; 'should': 0.40; 'best': 0.61; 'method': 0.61; "there's":
 0.61; 'mental': 0.62; 'come': 0.62; 'ever': 0.63; 'feel': 0.63;
 'between': 0.63; 'your': 0.64; 'overall': 0.64; 'produce': 0.65;
 'bad': 0.67; 'items': 0.68; 'order': 0.69; 'closing': 0.69;
 'received:202': 0.69; 'refers': 0.69; 'contact': 0.70;
 'essential': 0.70; 'longer': 0.71; 'covered': 0.75; 'solutions.':
 0.75; '(e.g.,': 0.76; 'implemented': 0.76; 'poor': 0.76; 'leads':
 0.81; 'cleaner': 0.84; 'indices': 0.84; 'preceding': 0.84; 'rid':
 0.84; 'strings': 0.84; 'striving': 0.84; 'adams': 0.91; 'affect':
 0.91; 'door': 0.91; 'replacing': 0.91; 'suffer': 0.91; 'race':
 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 roelschroeven.net; h=cc:content-transfer-encoding:content-type
 :content-type:date:date:from:from:in-reply-to:in-reply-to
 :message-id:mime-version:references:reply-to:subject:subject:to
 :to; s=fm2; t=1730885763; x=1730972163; bh=+auYewGpzHRXTtOMrBJHY
 PIOD44U2p3mV3bbJr17d28=; b=KTsTsKy/HXo3RG8me6u4Dc9gI9KfH4vOk9HBC
 vRYctSILoiCTga/I6KOgyTOf2jBW3BrA4TriP2628OhTPuiEeFsgrUAWYPeWMhgT
 wcfm4GR+8V7DTtEmpC9aD9tPtHAGU0nbbi7+rucZVa/sLxZ89/YX4eaCOF/b0OLp
 8Xe/z5Wt7RrBOJY0LPB2AbyWDUDi/CdFJI5cFoT2mgf8h7CLBtlmWHsJ1bWeGfMs
 sT8WzzgZMflEOkjXpe/GGXl5yfhaM2tDfaPYDWPnxW8ayGXymxYYVEDX4XDGt6oW
 My8YvZn/3Kr0kwp8EDPsFTd3SOyyzhdJMw+EjnNmvcw1WlcJg==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:content-transfer-encoding:content-type
 :content-type:date:date:feedback-id:feedback-id:from:from
 :in-reply-to:in-reply-to:message-id:mime-version:references
 :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender
 :x-me-sender:x-sasl-enc; s=fm3; t=1730885763; x=1730972163; bh=+
 auYewGpzHRXTtOMrBJHYPIOD44U2p3mV3bbJr17d28=; b=abdDNecTuxFCNit7i
 eCqZ0Jl4A6KQ5OpEChcn0WzIg0gBFI6v2FrjkvcykfgKpsh9AZRkTmrxeaZ/fONH
 I0711wS4nFEiU9L15Rp+Ghmwxbpet05jFtNxFVUGTUzdkkXBAtYa0K0B7ThYhGkh
 X5TGzWW0b85kDj/xZDRato5i3wra2hxIx2T6wfVBc5ZFpTjwUQs6TY3Am0RM2hkD
 VaRjhR53sxCPUx9bSxPdtiN4VUtVruhWTuDhMqaxkftsE757fAn1hq5PXVT3GPg4
 2PhA9TrgxHuipoJ1geQyHh14ZRca4C9GL4FZ3XtRc8pSF1uQYAkXEYiqjOZgOrtI
 CcQlQ==
X-ME-Sender: <xms:gzgrZ1ehuHJTVNrJUBjZ32h9LylDcgF7YygqScpRpp288wtkRyz0aQ>
 <xme:gzgrZzP4ui_zanAFfAm3UKE7ibLMo18jiX-Ke5zbNkBit9bhwb0R4WmCXLnBYgI5L
 RUhXP2yLfFa>
X-ME-Received: <xmr:gzgrZ-jX_U1S3Cro8tKrtKh433jqTLMl4sc_KzoJJl1Wqs5EOyFgyuhrjzUhHpPk177PovTeZpWRCc4o7FG-M0BY0EAg-PtYrg2_nSngeXoFtNU>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrtddvgddtfecutefuodetggdotefrodftvf
 curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr
 tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuf
 fvfhfhjggtgfesthekredttddvjeenucfhrhhomheptfhovghlucfutghhrhhovghvvghn
 uceorhhovghlsehrohgvlhhstghhrhhovghvvghnrdhnvghtqeenucggtffrrghtthgvrh
 hnpeegjeffkeegvdevjeejhfegtddvhefhiefhleefhffgiedtvdeigeeiieegvdduhfen
 ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgvlh
 esrhhovghlshgthhhrohgvvhgvnhdrnhgvthdpnhgspghrtghpthhtohepuddpmhhouggv
 pehsmhhtphhouhhtpdhrtghpthhtohepphihthhhohhnqdhlihhsthesphihthhhohhnrd
 horhhg
X-ME-Proxy: <xmx:gzgrZ-_J0sO3I-ApKB9Erai39nb8uycY0K7baE7SMPVi0bsktutEyw>
 <xmx:gzgrZxt5xGirE3JCjjnIxlDycefJ5vrP-I1zdc5H4DrmqKNIv122dw>
 <xmx:gzgrZ9FuQLADNbZYQCHGJJogEMTRjxzbAbVBszTZFBfG0HtDXCDzcA>
 <xmx:gzgrZ4OGSMiTI1xJNEd3DXjgYiK_aYB4uD7GmQP04oO8q8NNm6_XVA>
 <xmx:gzgrZyWEeeWWo9Vn1LRjrovNqHbDnku6R1rw2WjQkGp985q857E_mDvC>
Feedback-ID: i8e5b41ae:Fastmail
User-Agent: Mozilla Thunderbird
Content-Language: nl, en-US
In-Reply-To: <700403c2-e052-4670-b2ec-eaf9b4babada@pandora.be>
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: <0779f355-ed05-43cb-aa05-1afded82246c@roelschroeven.net>
X-Mailman-Original-References: <700403c2-e052-4670-b2ec-eaf9b4babada@pandora.be>
Bytes: 10113

Op 5/11/2024 om 15:48 schreef Raymond Boute via Python-list:
> L.S.,
>
> Python seem to suffer from a few poor design decisions regarding 
> strings and lists that affect the elegance of the language.
>
> (a) An error-prone "feature" is returning -1 if a substring is not 
> found by "find", since -1 currently refers to the last item. An example:
This is IMO indeed not the best design decision. Fortunately there's an 
alternative: the "index" method on strings, which raises exception 
ValueError when the substring is not found, instead of returning -1. An 
example:

 >>> s = 'qwertyuiop'
 >>> s[s.index('p')]
'p'
 >>> s[s.index('a')]
Traceback (most recent call last):
   File "<pyshell#3>", line 1, in <module>
     s[s.index('a')]
ValueError: substring not found

> Moreover, using index -1 for the last item is a bad choice: it should 
> be len(s) - 1 (no laziness!).
> Negative indices should be reserved for elements preceding the element 
> with index 0 (currently not implemented, but a must for orthogonal 
> design supporting general sequences).
I don't agree, I think this is a case of "practicality beats purity". 
Being able to use negative indices to index from the end is often very 
useful in my experience, and leads to code that is much easier to grok. 
General sequences on the other hand is a concept that I don't see ever 
implemented in Python (or most other programming languages AFAIK). I 
think it would be wrong to avoid implementing a feature that's very 
useful in practice in order to keep the door open for a theoretical 
feature that's probably not even wanted in the language.
> (b) When using assignment for slices, only lists with the same length 
> as the slice should be acceptable, otherwise an error should be 
> given.  Anything that re-indexes items not covered by the slice is 
> against the essential idea of assignment. For changes that imply 
> re-indexing (e.g., inserting a list longer than the slice), Python 
> offers cleaner solutions.
Again I don't agree. I don't see anything wrong with replacing a part of 
a list with something that's longer, or shorter, or even empty. It's 
very practical, and I don't see how it's against the essential idea of 
assignment (or actually I'm not even sure what you mean by that).

Two closing remarks:

(1) I think that Python indeed has some warts, inconsistencies, gotchas. 
I think this is unavoidable in any complex system. Python got rid of a 
number of those in the transition from Python 2 to Python 3; others 
might remain forever. Overall though I feel Python is more consistent 
than most other programming languages I come in contact with.

(2) Design decisions are not necessarily wrong when they don't match 
your mental model, or don't match what you know from other languages. 
Often there are different valid options, each with their own tradeoffs.

-- 
"Programming today is a race between software engineers striving to build bigger
and better idiot-proof programs, and the Universe trying to produce bigger and
better idiots. So far, the Universe is winning."
         -- Douglas Adams