Page 2 of 2

Re: 10DOF Wing for Adafruit Huzzah ESP8266

Posted: Thu May 19, 2016 4:28 am
by pythoncoder
@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!

Re: 10DOF Wing for Adafruit Huzzah ESP8266

Posted: Thu May 19, 2016 7:12 am
by kfricke
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.

Re: 10DOF Wing for Adafruit Huzzah ESP8266

Posted: Thu May 19, 2016 8:47 am
by deshipu
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!
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.

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".

Re: 10DOF Wing for Adafruit Huzzah ESP8266

Posted: Thu May 19, 2016 8:55 am
by pythoncoder
Fair point.

Re: 10DOF Wing for Adafruit Huzzah ESP8266

Posted: Tue Jun 07, 2016 5:08 am
by pythoncoder
deshipu wrote:In my recent drivers, I decided to write things like:

Code: Select all

self.write(0x0032, 0x01)  #  REGISTER_BLAHBLAH = 0x01
instead of

Code: Select all

REGISTER_BLAHBLAH = const(0x0032)
...
self.write(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.

I wonder if it would make sense to add it to the driver guide in the wiki?
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:

Code: Select all

_id = const(0x123456)
This gives us the best of both worlds: zero RAM use with code which is easy to refactor ;)