[Tutor] What is the best approach to organizing the order of functions in a module?
Steven D'Aprano
steve at pearwood.info
Fri Mar 20 00:08:41 CET 2015
On Fri, Mar 20, 2015 at 09:09:16AM +1100, Ben Finney wrote:
> Use a page break (the U+000C FORM FEED) white space character on a line
> by itself, to break up the source code into conceptually-separate areas.
> Your text editor should have a way of navigating to the previous/next
> form-feed character, as a way of navigating your file at this level.
I thought I liked that idea, but I've since *almost* decided that giving
semantic meaning (section break) to \f characters is an anti-pattern.
(1) Not all editors allow you to insert, jump to, and see such page
breaks. Not even all programmer's editors. I think it's an Emacs and/or
Vim feature which is basically unheard of anywhere else.
(2) Page breaks are invisible whitespace. If you have a commit hook that
deletes trailing whitespace at the end of lines and normalises line
breaks, your page breaks may disappear.
(3) Because they are invisible, you need editor support to see them. You
may not be able to see them when using other tools (e.g. `cat
somefile.py`) or when printed out.
(4) Since a bare formfeed is invisible and meaningless, you're going to
need some sort of section heading, say:
# === Public functions ===
so the formfeed is in a sense redundent.
(5) Pedantic: Formfeeds aren't for section breaks, they're for page
breaks. Using them in this way is abuse.
--
Steve
More information about the Tutor
mailing list