Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Methods order #21

Open
ddundo opened this issue Apr 26, 2024 · 2 comments
Open

Methods order #21

ddundo opened this issue Apr 26, 2024 · 2 comments
Labels
question Further information is requested

Comments

@ddundo
Copy link
Member

ddundo commented Apr 26, 2024

Currently we do not order methods in any particular way, which hinders readability. Could we decide on an order and add it to the wiki?

There doesn't seem to be a PEP suggestion, but I guess most common ordering is: magic methods, public methods, private methods? And then alphabetically within them? I'm not sure what would be best

@ddundo
Copy link
Member Author

ddundo commented Apr 27, 2024

There is a nice flake8 extension for this: https://github.com/best-doctor/flake8-class-attributes-order. Unfortunately it's not implemented in ruff (yet) but we can take a look there and see what good ordering practices are

@jwallwork23
Copy link
Member

Hm. I am familiar with ordering methods according to private, protected, public in C++ but it's not something I've ever even thought about in Python.

Personally, I prefer the methods to "build up" in the sense that you start with the constructor (__init__), then have some foundational data structures/properties and getters, and then move on to more complicated methods that interact with other ones. (I realise there are probably parts of the codes where this isn't enforced - I've never really tried to). In any case, it would be impossible to automate with a tool (unless it was an AI!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
Development

No branches or pull requests

2 participants