I'm just starting out with FreeCAD programming and I would like some clarification regarding the naming conventions in Python. I have already looked at the related topics on the forum but it is still not clear to me. In most workbenches, there is a mix of mixedCase and CamelCase for functions and variables, instead of snake_case, which is also used, but more rarely for functions. I don't think these are mistakes because this is even the case in the Wiki example (below).
Code: Select all
class MyWorkbench (Workbench):
MenuText = "My Workbench"
ToolTip = "A description of my workbench"
Icon = """paste here the contents of a 16x16 xpm icon"""
def Initialize(self):
[...]
Gui.addWorkbench(MyWorkbench())
*Extract from PEP8 :
*Extract from Draft "naming policy" :"Function names should be lowercase, with words separated by underscores as necessary to improve readability.
Variable names follow the same convention as function names.
mixedCase is allowed only in contexts where that’s already the prevailing style (e.g. threading.py), to retain backwards compatibility."
• Follow PEP 8.
• snake_case_names.py for modules.
• variable_names_without_capitals for variables.
• CamelCaseClass for classes.
• CONSTANTS_USE_CAPITALS for constants.
• functions_without_capitals() for functions and class methods.
• Functions expected to return a value should indicate what is expected, so is_mesh_valid is a good name, but check_mesh is not a good name.
• Class names, method names, and variables that are auxiliary, and not meant to be part of the public interface should start with an underscore like _MyInternalClass or _my_small_variable.