[Python-ideas] Custom Code Folding: Standardized Rules and Syntax?

Rhodri James rhodri at kynesim.co.uk
Mon Jul 17 07:11:24 EDT 2017


On 16/07/17 16:15, Steven D'Aprano wrote:
> Hi Connor, and welcome!
> 
> On Sun, Jul 16, 2017 at 10:37:26AM -0400, Connor Farrell wrote:
>> Background: I work in scientific computing and use Community Pycharm IDE.
>> In the end, I end up with very well folded code (except for large parameter
>> lists) and a bunch of co-workers asking about all the "editor-fold"
>> comments that don't work in their API.
> 
> I'm afraid I'm not understanding you here either. What's an
> "editor-fold" comment? What do they mean by API? API for which
> application? How does the programming interface to an application relate
> to code folding in a text editor?

The usual mechanism for folding (in those editors that don't think they 
know best) is to delimit them with comments that start with a particular 
sequence of characters.  You might have:

class Shrubbery:
   def __init__(self, size, planting, rockery=False):
     # {{{ Boring bits you don't need to see
     self.size = size
     self.rockery = rockery
     # }}}
     self.cost = complicated_function_of(planting)

...and so on.

>> Python was a trail-blazer in terms of emphasizing the importance of code
>> readability and effective syntax. I think that we should consider some sort
>> of standard for folding comments, if not only to promote stronger code
>> organizations. I know standards don't usually interact with IDEs, but hey,
>> the 'typing' module is pretty dang nice.
>>
>> TL;DR: Code folding is great, custom code folding is great, let's upgrade
>> it to a language feature.
> 
> What does that even mean? Are you suggesting that the Python interpreter
> should raise a SyntaxError or something if your code was written in an
> editor that didn't support code folding? How would it know?
> 
> Python is a programming language. The source code is text. I should be
> able to write Python code in NotePad if I want. Why should the Python
> core devs try to force every text editor and IDE fold code exactly the
> same way? That sounds awful to me. People choose different editors
> because they like different features, and that may include the
> particular way the editor folds code. Or to not fold it at all.
> 
> I'm sorry to be so negative, but I don't understand your proposal, and
> the bits that I *think* I understand sound pretty awful to me. Perhaps
> you can explain a bit better what you mean and why it should be a
> language feature, apart from "I want everyone to lay out their source
> code the way I do". Because that's what it sounds like to me.

I think I do understand the proposal, but I still agree with Steven. 
Folding is a feature of IDEs, not languages, and trying to legislate 
about it in a language definition is a bad plan.  I say this as someone 
who wrote a folding editor to make programming in Occam bearable :-)

-- 
Rhodri James *-* Kynesim Ltd


More information about the Python-ideas mailing list