10DOF Wing for Adafruit Huzzah ESP8266

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
User avatar
pythoncoder
Posts: 3060
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: 10DOF Wing for Adafruit Huzzah ESP8266

Post by pythoncoder » Thu May 19, 2016 4:28 am

@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

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: 10DOF Wing for Adafruit Huzzah ESP8266

Post by kfricke » Thu May 19, 2016 7:12 am

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.

User avatar
deshipu
Posts: 1333
Joined: Thu May 28, 2015 5:54 pm

Re: 10DOF Wing for Adafruit Huzzah ESP8266

Post by deshipu » Thu May 19, 2016 8:47 am

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

User avatar
pythoncoder
Posts: 3060
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: 10DOF Wing for Adafruit Huzzah ESP8266

Post by pythoncoder » Thu May 19, 2016 8:55 am

Fair point.
Peter Hinch

User avatar
pythoncoder
Posts: 3060
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: 10DOF Wing for Adafruit Huzzah ESP8266

Post by pythoncoder » Tue Jun 07, 2016 5:08 am

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 ;)
Peter Hinch

Post Reply