python-editor-v3 icon indicating copy to clipboard operation
python-editor-v3 copied to clipboard

Duplicated Neopixel 'show'

Open DaveAtKitronik opened this issue 3 years ago • 3 comments
trafficstars

The neopixel api has show() and write() functions: image

They appear to do the same thing, but one is for V2 only. This seems unnecessary duplication, with the potential to cause a slightly mystifying failure if a user only has a V1 micro:bit: image

The autocomplete lists all the things: image

I haven't managed to find any 'code' implementing the new write function in the micropython repo (https://github.com/bbcmicrobit/micropython) so can't see why there is a V2 version.

Would suggest removing the duplicate write(), and leaving the show() as this has been the API forever.

DaveAtKitronik avatar Oct 11 '22 12:10 DaveAtKitronik

Thanks @DaveAtKitronik. I've asked the team for input as I don't know the full context for this addition and will follow up as I find out more.

It's not new in the V3 Python Editor. It was added in MicroPython for micro:bit V2. We think it might have been added to align with other MicroPython ports (example), but I'm not sure of this yet.

What we have in the Python Editor API tab and autocomplete was derived from this documentation which covers both show and write but doesn't give any context.

MicroPython for micro:bit V2 can be found in its own repo. Checking there confirms that the functions are the same.

I'll follow up when I know more. I doubt we can remove it at this point due to backwards compatibility. One thing that would help, that we hope to do in future, is to add Reference tab documentation for Neopixels (in addition to the terser API documentation). That could then prioritise the approach that works on V1 and V2 micro:bits.

microbit-matt-hillsdon avatar Oct 12 '22 11:10 microbit-matt-hillsdon

The 'same' functionality isn't the issue - although duplication is not great. The fact the new one doesn't work for older microbits will cause issues in the classroom - especially where there are mixes of V1 and V2 microbits being used.

I hadn't seen it before yesterday, but that's probably because I don't expect APIs to change, and we have to make as much as possible work on V1 and V2, so wouldn't be looking for V2 only API changes.

DaveAtKitronik avatar Oct 12 '22 12:10 DaveAtKitronik

We've just confirmed with Damien that, indeed, the V2 write() method is included for compatibility with upstream MicroPython - we expect people to use show() in all cases on micro:bit. I don't think it's worth removing write() because it's useful for people using code shared across other MicroPython boards (on a V2), but when we add 'Reference' documentation for Neopixel, we'll only use V1/V2 compatible APIs for the common features.

jaustin avatar Oct 24 '22 10:10 jaustin