I also use PyCharm but I don't fold comprehensions; ideally I don't have to since comprehensions are meant to be simple and concise. Folding a comprehension takes away all the information, including the input to the operation.

Regarding names, the example function you presented, `clean`, isn't very expressive. For example `strip_and_filter_empty_lines` would be clear about the involved operations. Naming the result instead would be something like `stripped_and_empty_lines_removed`. Not very nice, especially when you're reusing that name elsewhere you carry around that verbosity. It's easier and cleaner to name actions than the result of those actions. And again, with a function call it's clear where the result originates from (the function argument) but a folded comprehension hides that information.

One of the points of using a function is to not define it in the local scope, but in some other namespace, so it can be reused and tested. Even if you find the need to define a local non-one-liner, prefixing it with an underscore most likely prevents name clashes and even if not PyCharm will readily report the problem.
On 2/22/20, 10:15 Alex Hall <alex.moj...@gmail.com> wrote:
1. At least in my editor (PyCharm), I can collapse (fold) list comprehensions just as easily as functions.
2. In this example the list comprehension already has a name - `clean_lines`. Using a function actually forces me to come up with a second pointless name.
3. On the note of coming up with names, if I want to use a local function (which I often do) then I also have to worry about names in two scopes clashing, and might invent more pointless names.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/SPWPNOCSZMOFAF45XYDCXD4MQR5LKXZO/
Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/FLKGHCVNDUWGBVRM3YEQVPRJXCI5KHR4/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to