10DOF Wing for Adafruit Huzzah ESP8266
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: 10DOF Wing for Adafruit Huzzah ESP8266
@deshipu I take your point about RAM but it's perhaps worth observing that PEP 8 states 'Use inline comments sparingly.' In some drivers you'd end up with comments on most lines!
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: 10DOF Wing for Adafruit Huzzah ESP8266
And Damien once did suggest to use simple comment lines (starting with '#'). They can be skipped most efficiently by the compiler. Docstrings (encapsulated with '"""....""") should be avoided.
I tend to simply use the registers etc by their smallest (in characters) notation. The use should be straightforward for the competent reader/writer of a driver. I see no point anymore in polishing code for readability, which only one with the documenting datasheet at hand will look at.
That is why I try to include the URL for the datasheet provided by the vendor.
Frozen bytecode is a completely different situation.
I tend to simply use the registers etc by their smallest (in characters) notation. The use should be straightforward for the competent reader/writer of a driver. I see no point anymore in polishing code for readability, which only one with the documenting datasheet at hand will look at.
That is why I try to include the URL for the datasheet provided by the vendor.
Frozen bytecode is a completely different situation.
Re: 10DOF Wing for Adafruit Huzzah ESP8266
It's also worth noting, that pep8 is a style guide to follow for those who contriubute to the cpython projetct itself, and, while it influences the style decisions for many other Python projects, doesn't apply outside of that context. I think that technical considerations, like in this case, certainly trump any style guide rule, especially when that style guide is for a different project.pythoncoder wrote:@deshipu I take your point about RAM but it's perhaps worth observing that PEP 8 states 'Use inline comments sparingly.' In some drivers you'd end up with comments on most lines!
Speaking of pep8, the micropython project itself, and especially its library and hardware api, don't follow the style either. I especially cringe at the arbitrarily abbreviated variable names, such as "addr" for "address" or "freq" for "frequency".
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: 10DOF Wing for Adafruit Huzzah ESP8266
Fair point.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: 10DOF Wing for Adafruit Huzzah ESP8266
You may be interested in https://github.com/micropython/micropyt ... dc8edd5e0a. MicroPython now treats variables named with a leading underscore and declared as const() as private to the module with no RAM being used:deshipu wrote:In my recent drivers, I decided to write things like:instead ofCode: Select all
self.write(0x0032, 0x01) # REGISTER_BLAHBLAH = 0x01
I think it's as readable (or even more), and at the time saves memory. The only down side is that you don't get to use the constants from outside of the library, but usually you never want to anyways.Code: Select all
REGISTER_BLAHBLAH = const(0x0032) ... self.write(REGISTER_BLAHBLAH, 0x01)
I wonder if it would make sense to add it to the driver guide in the wiki?
Code: Select all
_id = const(0x123456)
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.