Issue 11425: Cleanup sample code spacing and block arrangement in tutorial. (original) (raw)

Created on 2011-03-07 05:44 by methane, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cleanup_tutorial_codes.patch methane,2011-03-07 05:44 review
Messages (5)
msg130225 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2011-03-07 05:44
* Insert spaces around operators and after commas. * Split one liner blocks (ex. def foo(x, y): return x + y) to multi-line blocks. * Insert empty line after def block for scripts (not interactive mode). * Use new-style raise (s/ralse KeyboardInterrupt/raise KeyboardInterrupt()/) * Use x ** 3 instead of x * x * x. Attached patch is for Python 2.6. I'll make same changes for Python 3.1 if this patch is accepted.
msg130227 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2011-03-07 06:16
This patch inserts spaces around ** operator but I prefer no spaces around **. Any thoughts?
msg130230 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-03-07 07:14
Sorry, but I think many of these changes should not be made. Sometime the tight spacing is used for visual grouping. The following look fine and should not be changed because adding spaces around the + or * operator makes the whole sentence harder to mentally parse correctly: sum(x*y for x,y in zip(xvec, yvec)) a, b = b, a+b Also, it is perfectly correct to use: raise StopIteration We use the parentheses when there is an argument: raise KeyError('key not found: {!r}'.format(k)) Sometimes one-liners are okay in the interactive mode for quick filter functions and whatnot. Spreading them out with '...' lines makes the example harder to follow and expands the set-up part of the example rather than the part being explained. It's perfectly valid to use x * x * x instead of x**3 in an example of how to use map. We want the example to be as simple as possible. Also, the interactive prompt examples should be left as-is. They communicate the free-form nature of experimentation at the prompt.
msg130234 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-03-07 07:33
I made the c -> cls change in 88fe1ac48460. Some other fixes have already been made in py3k (like removing the duplicate index keyword), and for the others I completely agree with Raymond.
msg130248 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-03-07 10:59
Just two notes: The operations like “7205759403792794 * 10**30 / 2**56” in floatimport could use some parens; the patch removed a duplicate “statement: for” entry.
History
Date User Action Args
2022-04-11 14:57:14 admin set github: 55634
2020-05-14 05:51:20 Chas Belov set title: Cleanup sample codes in tutorial. -> Cleanup sample code spacing and block arrangement in tutorial.
2011-03-07 10:59:32 eric.araujo set nosy: + eric.araujomessages: +
2011-03-07 07:33:27 georg.brandl set resolution: rejected -> fixedmessages: + nosy: + georg.brandl
2011-03-07 07:14:07 rhettinger set status: open -> closednosy: + rhettingermessages: + resolution: rejected
2011-03-07 06:16:24 methane set nosy:methane, docs@pythonmessages: +
2011-03-07 05:44:52 methane create