Sujet : Re: Two python issues
De : cs (at) *nospam* cskk.id.au (Cameron Simpson)
Groupes : comp.lang.pythonDate : 05. Nov 2024, 23:06:12
Autres entêtes
Message-ID : <mailman.82.1730840778.4695.python-list@python.org>
References : 1 2
User-Agent : Mutt/2.2.13 (2024-03-09)
On 05Nov2024 15:48, Raymond Boute <
raymond.boute@pandora.be> wrote:
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.
`find` is a pretty old API interface. It is what it is. It may obtain some of its design choices from C style calls where returning -1 for failure was a common idiom.
If "find" is unsuccessful, an error message is the only clean option.
This is not true. Often we want to look for something, and act one way or another depending on whether it is found. I've got plenty of loops and other tests which more or less go "run until this is not found". It is not an error, it is just a circumstance to accomodate.
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).
It is _far_ too late to propose such a change.
Plenty of us are quite hapoy with negative indices. We just view them as counting backwarss from the end of the string or sequence instead of forwards from the beginning.
(b) When using assignment for slices, only lists with the same length as the slice should be acceptable, otherwise an error should be given.
There are many many circumstances where we replace a subsequence with a different subsequence of different length. Outlawing such a thing would remove and extremely useful feature.
Cheers,
Cameron Simpson <
cs@cskk.id.au>