Skip to content

Commit f6cdfa9

Browse files
committed
Update after feedback from @deshipu. Thanks
1 parent 7ab7f41 commit f6cdfa9

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

docs/design_guide.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,27 @@ provide `__enter__` and `__exit__` to create a context manager usable with `with
3838

3939
## Verify your device
4040

41-
Make sure device you are talking to is the device you expect. If not, raise a
42-
ValueError. Beware that I2C addresses can be identical on different devices so
43-
read registers you know to make sure they match your expectation. Validating
44-
this upfront will help catch mistakes.
41+
Whenever possible, make sure device you are talking to is the device you expect.
42+
If not, raise a ValueError. Beware that I2C addresses can be identical on
43+
different devices so read registers you know to make sure they match your
44+
expectation. Validating this upfront will help catch mistakes.
4545

4646
## Getters/Setters
4747

4848
When designing a driver for a device, use properties for device state and use
49-
methods for actions that the device performs. Doing this well helps beginners
50-
understand when to use what. It is also consistent with
49+
methods for sequences of abstract actions that the device performs. State is a
50+
property of the device as a whole that exists regardless of what the code is
51+
doing. This includes things like temperature, time, sound, light and the state
52+
of a switch. For a more complete list see the sensor properties bullet below.
53+
54+
Another way to separate state from actions is that state is usually something
55+
the user can sense themselves by sight or feel for example. Actions are
56+
something the user can watch. The device does this and then this.
57+
58+
Making this separation clear to the user will help beginners understand when to
59+
use what.
60+
61+
Here is more info on properties from
5162
[Python](https://docs.python.org/3/library/functions.html#property).
5263

5364
## Design for compatibility with CPython
@@ -61,14 +72,27 @@ modules to add extra functionality. By distinguishing API boundaries at modules
6172
you increase the likelihood that incorrect expectations are found on import and
6273
not randomly during runtime.
6374

75+
### Example
76+
When adding extra functionality to CircuitPython to mimic what a normal
77+
operating system would do, either copy an existing CPython API (for example file
78+
writing) or create a separate module to achieve what you want. For example,
79+
mounting and unmount drives is not a part of CPython so it should be done in a
80+
module, such as a new `filesystem`, that is only available in CircuitPython.
81+
That way when someone moves the code to CPython they know what parts need to be
82+
adapted.
83+
6484
## Document inline
6585

6686
Whenever possible, document your code right next to the code that implements it.
6787
This makes it more likely to stay up to date with the implementation itself. Use
6888
Sphinx's automodule to format these all nicely in ReadTheDocs. The cookiecutter
6989
helps set these up.
7090

71-
Use [rST](http://docutils.sourceforge.net/docs/user/rst/quickref.html) for markup.
91+
Use [Sphinx flavor rST](http://openalea.gforge.inria.fr/doc/openalea/doc/_build/html/source/sphinx/rest_syntax.html) for markup.
92+
93+
Lots of documentation is a good thing but it can take a lot of space. To
94+
minimize the space used on disk and on load, distribute the library as both .py
95+
and .mpy, MicroPython and CircuitPython's bytecode format that omits comments.
7296

7397
### Module description
7498

@@ -148,6 +172,9 @@ object with methods that read or write into the buffer instead of creating new
148172
objects. `nativeio` classes are design to read and write to subsections of
149173
buffers.
150174

175+
Its ok to allocate an object to return to the user. Just beware of causing more
176+
than one allocation per call due to internal logic.
177+
151178
**However**, this is a memory tradeoff so do not do it for large or rarely used
152179
buffers.
153180

0 commit comments

Comments
 (0)