Zolko wrote: ↑Thu Dec 19, 2019 8:54 am
...
The longer answer is: as you could see, I don't know how to do all the things that you're saying (or I'd have done it before), so If you have proposals please feel free to do so.
The basic PEP8 document that you will hear about a lot is this one:
PEP 8 -- Style Guide for Python Code. Take your time to read it.
Also important is
PEP 257 -- Docstring Conventions.
These two documents are the basis of good Python style, and most important libraries in the Python world follow these guidelines. If you use a Python focused editor like Spyder, it will automatically point things that can be improved in your code. Otherwise you can run an external tool like
flake8, or
pycodestyle, to point out where you can improve the code.
The previous documents are a bit too technical, so I prefer nicer documents that explain them.
*
How to Write Beautiful Python Code With PEP 8
*
Documenting Python Code: A Complete Guide
I could work through your code little by little, but since I'm busy looking into other parts of FreeCAD, I think you can change the style yourself also little by little, as you become familiar with Python recommendations. As I said, it's not extremely important, it's mostly about style. A library that complies with PEP8 immediately feels more familiar and easier to extend by Python programmers.
One thing that I will try to change is the naming style of methods and functions. Since the core of FreeCAD uses C++, many functions use the
camelCase style. But Python dislikes this completely and prefers
snake_case. If you already have public functions that must be kept, then I suggest using the
snake_case convention but creating an alias to the previous name, like this.
Code: Select all
def snake_case:
...
snakeCase = snake_case
Then the same function can be called as
snake_case() (official style) or
snakeCase() (legacy style, which should be deprecated in the future).