Python Forum

Full Version: Naming convention advice
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I recently went over all methods of a project to regroups them by reverse naming, alphabetical order, and type (third party, private, public). Finally I added an underscore in front of all private methods. One of the class is a GUI for preferences (PreferencesForm), which contain only private methods. The class is huge and is only called as a standalone instance, so should I still prefix all methods with an underscore?

You can take a look at the module here:
https://gitlab.com/william.belanger/qtpa...erences.py
Post your code here, using BBCode tags.
As the code is not very relevant, here is a summary of two modules. On the left the methods are sorted and internals are marked with an underscore, on the right all methods are internals so they have no _prefix. I used CapitalizedWords to stay consistent with PyQt style (as recommended in PEP8).

[Image: Untitled.png]
Please read forum rules, especially BBCode (as suggested in previous post). Please do not post images. You can run the code through pep8: https://pypi.org/project/pep8/upgraded to pycodestyle: https://pypi.org/project/pycodestyle/
this will point out non complaint naming. Generally Camel case is reserved for Class names, and functions and methods use snake case (lower case and underscores)
Thanks for the tips. I already looked over the code with flake and pep8 utilities. I don't need advices about the code itself, but I am rather wondering about the labeling of private methods. To make it more clear, my question is does it make sense to mark all methods as private when there are no public methods? It seems like it would not give much useful informations. Or maybe there is a convention for this particular case? Unfortunatly after reading through PEP8 I did not found a definitive answer.

As for the CamelCase, as I wrote earlier I know that the snake_case is usually recommended, but as I work with Qt framework, consistency is preferred. As written in PEP8:

Quote:New modules and packages (including third party frameworks) should be written to these standards, but where an existing library has a different style, internal consistency is preferred.
I understand (though I can be very wrong) private methods are only cosmetic, and not enforced.
Usually a single starting underscore for private.
Not much help here.

Quote:but as I work with Qt framework, consistency is preferred
I agree with that.