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

Connor Farrell cgfarrellchg at gmail.com
Sun Jul 16 10:37:26 EDT 2017

Background: I work in scientific computing and use Community Pycharm IDE.

I'm a religious follower of the 'readability counts' mantra, and two things
I find myself doing often are:
- Writing custom code folds to segregate code, from groups of classes in a
file, to groups of lines in an individual function. While spacing works
great to separate ideas, my IDE allows me to collapse the entirety of the
code in exchange for a line of English. For my purposes, this enhances
readability immensely, as first time users are confronted with an
explanation of the contents, rather than the code itself with a comment on
top. I find comments don't draw the eye, and also don't have the ability to
their code as well.
- Writing high level code, such as __init__ calls for large aggregates,
with one keyworded argument per line (plus dict unpackings at the end),
sort of like a simple XML file. This allows me to make parameters explicit
for other users, and optionally provide a comment indicating physical
units, cite sources, and/or give a list of tag/enum options for every
parameter. In the end I have 30+ line inits, but the readability is 10x
greater. My IDE doesn't yet offer to fold long parameter lists by default,
but I think it makes sense.

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.

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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170716/c53f720a/attachment-0001.html>

More information about the Python-ideas mailing list