From b3d75d977e037dfbe3d6d1ffd90e535e99cfd703 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Fri, 13 Mar 2020 08:56:05 +0100 Subject: [PATCH] FEM: extend code conventions --- src/Mod/Fem/coding_conventions.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Mod/Fem/coding_conventions.md b/src/Mod/Fem/coding_conventions.md index 37a02e82ea..a3496a6cf0 100644 --- a/src/Mod/Fem/coding_conventions.md +++ b/src/Mod/Fem/coding_conventions.md @@ -24,7 +24,7 @@ These coding rules apply to FEM module code only. Other modules or the base syst - a .gitattributes file has been added to ensure line endings of text files are LF - use `?w=1` in link address to suppress line ending changes on github - never use mixed line endings on one file -- 4 Spaces for indent +- 4 Spaces for indent (in this file too ;-)) - no trailing white spaces @@ -78,15 +78,23 @@ find src/Mod/Fem/ -name "*\.py" | grep -v InitGui.py | xargs -I [] flake8 --igno ### Coding - print() vs. FreeCAD.Console.PrintMessage() - - `FreeCAD.Console.PrintMessage()` or Log or Error should be used - - `print()` should be used for debugging only - - [forum topic](https://forum.freecadweb.org/viewtopic.php?f=10&t=39110) - - BTW: Console prints need a new line where as print does not need one + - `FreeCAD.Console.PrintMessage()` or Log or Error should be used + - `print()` should be used for debugging only + - [forum topic](https://forum.freecadweb.org/viewtopic.php?f=10&t=39110) + - BTW: Console prints need a new line where as print does not need one +- type checking: + - do not use hasattr(obj, "Proxy") and obj.Proxy.Type + - use method is_of_typ(obj, "TypeString") from module femtool.femutils +- ActiveDocument + - do not use App.ActiveDocument or FreeCAD.ActiveDocument, if possible + - use some_obj.Document instead + - do not use Gui.ActiveDocument or FreeCADGui.ActiveDocument, if possible + - use some_obj.ViewObject.Document or some_view_obj.Document ### Documenting Python style is preferred over Doxygen style - - see `ccx` tools module in fem tools package - - see [forum topic](https://forum.freecadweb.org/viewtopic.php?f=10&t=37094) + - see `ccx` tools module in fem tools package + - see [forum topic](https://forum.freecadweb.org/viewtopic.php?f=10&t=37094) ## C++ ### Naming policy