|
| 1 | +# Contributing Example Scripts |
| 2 | + |
| 3 | +Use this guide when adding or updating scripts in `examples/`. |
| 4 | + |
| 5 | +## Must-have checklist before opening a PR |
| 6 | + |
| 7 | +1. Script teaches one clear thing (its primary learning goal). |
| 8 | +2. File name matches that goal. |
| 9 | +3. Top docstring states purpose, transport scope, behavior, and expected output. |
| 10 | +4. Script has safe shutdown (`with ...` or `finally`) and graceful `KeyboardInterrupt` handling. |
| 11 | +5. Argument handling is clear (`argparse` preferred). |
| 12 | +6. Errors are explicit (no bare `except:`). |
| 13 | +7. The script is not a near-duplicate of an existing example. |
| 14 | + |
| 15 | +## Choose the right teaching goal |
| 16 | + |
| 17 | +Each example should have one primary lesson. Keep it focused. |
| 18 | + |
| 19 | +- Good: "Send one text message over serial." |
| 20 | +- Good: "Print inbound text messages." |
| 21 | +- Avoid: discovery + chat + config mutation all in one script unless that combined flow is the lesson. |
| 22 | + |
| 23 | +## Transport scope must be explicit |
| 24 | + |
| 25 | +State exactly what transports are supported and why. |
| 26 | + |
| 27 | +- Serial-only when that keeps the example simplest. |
| 28 | +- Multi-transport (Serial/TCP/BLE) only when transport selection is part of the lesson. |
| 29 | +- If TCP/BLE are supported, expose explicit flags (`--host`, `--ble`) and document defaults. |
| 30 | + |
| 31 | +## Behavior and output should be predictable |
| 32 | + |
| 33 | +Readers should know if the script sends, receives, mutates config, or combines those. |
| 34 | + |
| 35 | +- Receive examples: subscribe to the narrowest pubsub topic that matches the lesson. |
| 36 | +- Send examples: clarify destination behavior (broadcast default vs explicit destination). |
| 37 | +- Mutation examples: clearly document side effects. |
| 38 | + |
| 39 | +Output should make success easy to confirm: |
| 40 | + |
| 41 | +- Print concise, stable status/event lines. |
| 42 | +- Avoid noisy debug output unless the script is specifically diagnostic-focused. |
| 43 | + |
| 44 | +## Cleanup and error handling |
| 45 | + |
| 46 | +- Use context managers where practical; otherwise close interfaces in `finally`. |
| 47 | +- Handle `KeyboardInterrupt` cleanly. |
| 48 | +- Exit non-zero for invalid args, connection/setup failures, or command failures. |
| 49 | + |
| 50 | +## Naming guidance |
| 51 | + |
| 52 | +Use descriptive names tied to the teaching goal. |
| 53 | + |
| 54 | +- Prefer names like `tcp_connection_info_once.py` over `pub_sub_example.py`. |
| 55 | +- Prefer names like `tcp_pubsub_send_and_receive.py` over `pub_sub_example2.py`. |
| 56 | +- Avoid generic names such as `example2.py`. |
| 57 | + |
| 58 | +Keep existing filenames only when compatibility or discoverability outweighs clarity. |
| 59 | + |
| 60 | +## New script vs extending an existing one |
| 61 | + |
| 62 | +Create a new script when: |
| 63 | + |
| 64 | +- The learning goal is genuinely distinct. |
| 65 | +- Combining behaviors would make either example harder to understand. |
| 66 | + |
| 67 | +Extend an existing script when: |
| 68 | + |
| 69 | +- The change deepens the same lesson. |
| 70 | +- The resulting script remains focused and readable. |
0 commit comments