[Microbit-Python] Flat API

Michael sparks.m at gmail.com
Tue Sep 22 13:15:26 CEST 2015


Hm. Good points. I can see the argument for ruling out python properties as
well.

That said, from a user perspective, I'm not convinced that mb.dpin0 = True
(or rather microbit.dpin0 = True) is unclear.

[ actually scratch that, writing this has convinced me that any variation
on properties is a bad idea, but I'll leave the next bit to explain why
I've convinced myself ]

After all, we say "this is something that can be set by the microbit
runtime, as well as the child" then that approach isn't actually far off
how the  prototype's DAL actually worked. (For good or ill)

In particular this:

    pixel[0,0] =

Which could map to (perhaps):

    microbit.pixel[0,0] =

Is actually really close to this code that was valid C code:

void set_point(uint8_t x, uint8_t y, uint8_t state) {
    if (x <0) return;
    if (x >DISPLAY_WIDTH-1) return;
    if (y <0) return;
    if (y >DISPLAY_HEIGHT -1) return;
    display[x][y] = state;
}

(This is a copy and paste of the code that underlined "plot/unplot" in
the prototype's DAL :-) )

I mainly mention this because for somethings - like structures - this
*might* be a good approach.

For example:

from microbit import dpins
from microbit import apins
from microbit import display

pin[0] = True
reading = apins[0]
display[0,0] = 1

I must admit, now I've typed that, I think this approach might actually end
up confusing a child. Having everything as an explicit function - though in
a flat namespace - is probably better?

from microbit import *

set_dpin(0, True)
set_dpin(0, False)
pressed = getButton("A")
reading = measure_analog_pin(0)

That said, a flat namespace of functions is precisely what the prototype
DAL was so, that might be worth a look :-)


Michael.

On 22 September 2015 at 11:46, Tom Viner <tom at viner.tv> wrote:

>
> On 22 September 2015 at 10:35, Alan <alainjackson at hotmail.com> wrote:
>
>> Both the full standard API and the flat one, yes, that's great.  I like
>> "mb" as the module name.
>
>
> I don't actually think dpin0 = True is pythonic if that does anything
> other than set (and completely override) a variable value. And I think we
> agreed yesterday that standard properties were an extra concept to explain,
> and furthermore not introspectable. So that rules out mb.dpin0 = True too.
>
> To avoid confusion with duplicate modules and top level properties, can we
> agree that the "flat api" is simply "from microbit import *" and that's the
> way you dump a load of module names into the global namespace.
>
>
>
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/mailman/private/microbit/attachments/20150922/fb133909/attachment-0001.html>


More information about the Microbit mailing list