From 4861a0d958f0ccc9d1dcca14dd9f8550dc47309c Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 16 Nov 2021 19:25:34 -0500 Subject: [PATCH] docs: Add recommendation on Python type handling to Code_Overview.md Signed-off-by: Kevin O'Connor --- docs/Code_Overview.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/Code_Overview.md b/docs/Code_Overview.md index 170185b7..bd8c3075 100644 --- a/docs/Code_Overview.md +++ b/docs/Code_Overview.md @@ -311,6 +311,16 @@ The following may also be useful: * Avoid accessing the internal member variables (or calling methods that start with an underscore) of other printer objects. Observing 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 sure to place a copyright notice at the top of the module. See the existing modules for the preferred format.