-
Notifications
You must be signed in to change notification settings - Fork 0
Best Practices
Nathan Keidel edited this page Mar 17, 2024
·
1 revision
- Minimize redundancy. Avoid having multiple pieces of code doing the exact same thing.
- Comment the code. Anyone should be able to open the code up and figure out what any given line does from the comments.
- If a variable has units, note the unit in a comment on the variable's declaration.
- Delete code that we are not using anymore instead of commenting it out. If we need to look at it, we can use an old commit.
- Adhere to Python naming conventions rather then the naming conventions for FRC C++ code.
- Use functionality from standard lib + RobotPy rather then installing new dependencies whenever possible (eg, using RobotPy's unit conversion module instead of importing another library for it).
- Make sure you are using the latest version of any robotpy and wpilib related libraries
- Make sure the latest robotpy version is specified in the 'pyproject.toml' file
- Commands to update all pip packages:
- WINDOWS:
pip freeze | %{$_.split('==')[0]} | %{pip install --upgrade $_}
- LINUX:
pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U
- WINDOWS:
- Disable the VSCode settings "Editor: Insert Spaces" and "Detect Indentation". Use tabs instead of spaces everywhere no mater what.
- Use this wiki to store high-level documentation (eg, descriptions of mechanisms and what they do).
- Use branches to keep track of code for different mechanisms, merge to main when we reach stability.
- Use tags to mark stable "versions" (eg, a tag for the version of the code used at each competition).
If you plan on using the debug messages module (located at 'modules.debugmsgs.py') follow these practices so all output is uniform
-
Always start a message with a capital letter -> EX:
modules.debugmsgs.debugMsg('Testing')
- Error messages must include the traceback and have a detailed (but short) message -> EX:
modules.debugmsgs.errorMsg('Error getting motor status:', error,__file__) # Variable 'error' will be caught in a try/except logic
(whereerror
is a string variable with the traceback info.) - Error messages must also include a
:
at the end of each custom message