On 2010-11-03, D'Arcy J.M. Cain <da...@druid.net> wrote: > On Wed, 3 Nov 2010 00:41:46 +0000 (UTC) > Tim Harig <user...@ilthio.net> wrote: >> On 2010-11-02, D'Arcy J.M. Cain <da...@druid.net> wrote: >> Actually, I have found similar markers to be useful everywhere. I don't >> like the way my editor tries to fold Python code, so I started inserting >> folding markers myself: >> >> # foo {{{ >> if foo: > > Now that is redundant. We know it's "foo" at the top of the block.
In practice the comment would explain why and how the conditional is being used just like any other comment. Since your example as abstract, I didn't have anything useful to say about it as I would for real code. When the code is folded, I will see nothing but the comments. It is often helpful to look at a section of code with all of the code blocks folded to gain a high level understanding of the code before zeroing in on the specific section that I wish to edit. When I do edit a section, I unfold no more code blocks then necessary. If I have to unfold too many blocks to to edit a single section of code, then it is a powerful indication that either the code block is not properly self contained or that the comments of the surrounding code blocks are insufficient to convey information about their code block. > Identifying the end of the block has some value. And the braces just > make the code noisy. With good syntax highlighting, you don't notice them unless you are looking for something because the markers are in comments and the markers for a block are only visible when the block is unfolded. As a benefit, they allow the folding stucture to provide expression of the code structure that cannot be expressed in the code itself. I often group blocks together that would not otherwise be indented or otherwise expressed together as they were in your example. # top level group {{{ # part 1 {{{ code # }}} # part 2 {{{ code # }}} # part 3 {{{ code # }}} # }}} Folded in my editor, it looks like this: 44 +--- 15 lines: # top level group ------------------------------------------- Unfolding the top level group, it looks like this: 44 # top level group {{{ 45 46 +---- 3 lines: # part 1 --------------------------------------------------- 49 50 +---- 3 lines: # part 2 --------------------------------------------------- 53 54 +---- 3 lines: # part 3 --------------------------------------------------- 57 58 # }}} It is therefore clear that all three of the parts are logically connected. I can keep them all folded and view them as a group or a can look into the group and edit just the relevant section of the group: 44 # top level group {{{ 45 46 +---- 3 lines: # part 1 --------------------------------------------------- 49 50 # part 2 {{{ 51 code 52 # }}} 53 54 +---- 3 lines: # part 3 --------------------------------------------------- 57 58 # }}} I have effectively added a meta structure to the blocks inside of the fuction at a finer grain then is supported by the syntax itself. Should I decide later that the top level group is becoming autonomous enough to warrant moving to a separate function, I can simply grab the entire folded block as an entity and move it to its own function body. -- http://mail.python.org/mailman/listinfo/python-list