docs: Add recommendation on Python type handling to Code_Overview.md

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-11-16 19:25:34 -05:00
parent 779793c746
commit 4861a0d958
1 changed files with 10 additions and 0 deletions

View File

@ -311,6 +311,16 @@ The following may also be useful:
* Avoid accessing the internal member variables (or calling methods * Avoid accessing the internal member variables (or calling methods
that start with an underscore) of other printer objects. Observing that start with an underscore) of other printer objects. Observing
this convention makes it easier to manage future changes. this convention makes it easier to manage future changes.
* It is recommended to assign a value to all member variables in the
Python constructor of Python classes. (And therefore avoid utilizing
Python's ability to dynamically create new member variables.)
* If a Python variable is to store a floating point value then it is
recommended to always assign and manipulate that variable with
floating point constants (and never use integer constants). For
example, prefer `self.speed = 1.` over `self.speed = 1`, and prefer
`self.speed *= 2.` over `self.speed *= 2`. Consistent use of
floating point values can avoid hard to debug quirks in Python type
conversions.
* If submitting the module for inclusion in the main Klipper code, be * If submitting the module for inclusion in the main Klipper code, be
sure to place a copyright notice at the top of the module. See the sure to place a copyright notice at the top of the module. See the
existing modules for the preferred format. existing modules for the preferred format.