Re: [Python-ideas] Python-ideas Digest, Vol 128, Issue 41

Thanks for your feedback, I guess I was a little unclear. In short, I was thinking of a pair of comment tokens (something like #<<, #>>, idk) that would indicate a code fold, like what virtually all IDEs do for classes and methods, but with more granularity. It would allow devs to better organize their code. I agree with what you're saying about separation of language and text editor, but we already have the *typing* module in 3.6, so improved linting and communication is apparently game. I have no desire to get the interpreter involved, this is pure linter. A good example would be something like: class A: #<< INTERFACE def foo(): .... def bar(): .... #>> #<< BACKEND def _guts(): .... #>> Would become something like: class A: *>+ INTERFACE* * >+ BACKEND* Where *modern* editors should fold the code. It provides an optional additional layer of granularity above the current system, but has no effect on behaviour otherwise. It increases visual information density in complex functions, large classes, and lets you group classes. It looks stupid with only three functions, but at larger sizes, or with complex code, I'd rather see: def func(f: Callable[[float],float, float]) -> None: *>+* *Input validation* *>+ Some complex algorithm* * >+ Some other complex algorithm* * >+ Generating plot* It adds a human explanation of the code within, an additional level(s) of organization, and easier navigation. It's not for everyone, but I feel like it improves on the idea of modular code at for active devs, without any drawbacks for library users. On Sun, Jul 16, 2017 at 12:00 PM, <python-ideas-request@python.org> wrote:

Sorry I didn't see this answer (as the title changed, it was moved to another topic in my mailbox). So I still believe code-folding indications don't really belong to the source files. But what you're showing is interesting, and the code folding is just a consequence of it. It can be as chapters or sub-chapters, which might be a nice organization of the code. I'm not sure of the relevance of the closing code though: If they are like chapters, they describe the content until the next chapter, or until the scope ends (end of method, of function, of class, ...). So the IDE just need to parse those comments and implement a code folding method based on it. It could simply be `### [description]`, like `### Security features`. I think it could be a good help in some cases, like in a settings.py files (like Django's one which can be pretty long). But there are downsides: - We should try to avoid to write classes, methods or functions that are too long. It often means that it should be split into smaller functionalities. This would probably not push the developers in the right direction if we asked them to used such a tool. But I don't know if this big-pieces-of-code-is-a-code-smell-for-refactorisation is true for scientific development, as I imagine there can be some quite long pieces of codes that really are meant to be together. - It still enforces a way of coding. Some prefer to group their methods by functionality (everything related to security is in grouped for example), but others prefer to sort their methods alphabetically. Or by type of methods (higher level methods first, lower level last), etc. Also, what about magic methods, or methods that are shared between two or more functionalities? So I'm not sure how I feel about this, the discussion and examples may be interesting (more than what I understood from first mail anyway!). -Brice Le 16/07/17 à 18:42, Connor Farrell a écrit :

Many editors allow you to explicitly select blocks to fold rather than only basing it on explicit syntax in a code file. Obviously, the information on where those folds occurred is them generally stopped somewhere apart from the text of the code itself. It sounds like you should choose an editor that does that and/or a macro/extension/mode to your favorite editor to behave as you like. On Jul 16, 2017 11:27 AM, "Brice PARENT" <contact@brice.xyz> wrote:

Sorry I didn't see this answer (as the title changed, it was moved to another topic in my mailbox). So I still believe code-folding indications don't really belong to the source files. But what you're showing is interesting, and the code folding is just a consequence of it. It can be as chapters or sub-chapters, which might be a nice organization of the code. I'm not sure of the relevance of the closing code though: If they are like chapters, they describe the content until the next chapter, or until the scope ends (end of method, of function, of class, ...). So the IDE just need to parse those comments and implement a code folding method based on it. It could simply be `### [description]`, like `### Security features`. I think it could be a good help in some cases, like in a settings.py files (like Django's one which can be pretty long). But there are downsides: - We should try to avoid to write classes, methods or functions that are too long. It often means that it should be split into smaller functionalities. This would probably not push the developers in the right direction if we asked them to used such a tool. But I don't know if this big-pieces-of-code-is-a-code-smell-for-refactorisation is true for scientific development, as I imagine there can be some quite long pieces of codes that really are meant to be together. - It still enforces a way of coding. Some prefer to group their methods by functionality (everything related to security is in grouped for example), but others prefer to sort their methods alphabetically. Or by type of methods (higher level methods first, lower level last), etc. Also, what about magic methods, or methods that are shared between two or more functionalities? So I'm not sure how I feel about this, the discussion and examples may be interesting (more than what I understood from first mail anyway!). -Brice Le 16/07/17 à 18:42, Connor Farrell a écrit :

Many editors allow you to explicitly select blocks to fold rather than only basing it on explicit syntax in a code file. Obviously, the information on where those folds occurred is them generally stopped somewhere apart from the text of the code itself. It sounds like you should choose an editor that does that and/or a macro/extension/mode to your favorite editor to behave as you like. On Jul 16, 2017 11:27 AM, "Brice PARENT" <contact@brice.xyz> wrote:
participants (3)
-
Brice PARENT
-
Connor Farrell
-
David Mertz