CARVIEW |
Select Language
HTTP/1.1 200 OK
Date: Mon, 28 Jul 2025 03:24:18 GMT
Server: Apache/2.4.39 (Ubuntu)
Strict-Transport-Security: max-age=31556926
Upgrade: h2,h2c
Connection: Upgrade
Last-Modified: Fri, 31 Oct 2003 08:03:50 GMT
ETag: "d2c-3caf711882580-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 1405
Content-Type: text/html
[Python-Dev] sort() return value
Fri Oct 17 10:56:38 EDT 2003
More information about the Python-Dev mailing list
[Python-Dev] sort() return value
Guido van Rossum guido at python.orgFri Oct 17 10:56:38 EDT 2003
- Previous message: [Python-Dev] Trashing recursive objects comparison?
- Next message: [Python-Dev] accumulator display syntax
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I'd like to explain once more why I'm so adamant that sort() shouldn't return 'self'. This comes from a coding style (popular in various other languages, I believe especially Lisp revels in it) where a series of side effects on a single object can be chained like this: x.compress().chop(y).sort(z) which would be the same as x.compress() x.chop(y) x.sort(z) I find the chaining form a threat to readability; it requires that the reader must be intimately familiar with each of the methods. The second form makes it clear that each of these calls acts on the same object, and so even if you don't know the class and its methods very well, you can understand that the second and third call are applied to x (and that all calls are made for their side-effects), and not to something else. I'd like to reserve chaining for operations that return new values, like string processing operations: y = x.rstrip("\n").split(":").lower() There are a few standard library modules that encourage chaining of side-effect calls (pstat comes to mind). There shouldn't be any new ones; pstat slipped through my filter when it was weak. --Guido van Rossum (home page: https://www.python.org/~guido/)
- Previous message: [Python-Dev] Trashing recursive objects comparison?
- Next message: [Python-Dev] accumulator display syntax
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list