[Microbit-Python] Interval boundaries... what did we decide?

Nicholas H.Tollervey ntoll at ntoll.org
Mon Oct 12 10:41:34 CEST 2015


My 2c...

MicroPython is an implementation of Python 3 - ergo we should do what
Python does.

This is important because part of the selling point for using
MicroPython is that kids are learning the habits of a real programming
language they can graduate to on, say, a RPi.

It's more confusing for kids to learn one thing, then have to change
because "reasons".

N.

On 12/10/15 09:30, Larry Hastings wrote:
> On 10/12/2015 01:12 AM, Mark Shannon wrote:
>>
>> There is another way to express a range: (start, length).
>> For example, I have followed the DAL API for Image.crop() which is
>> Image.crop(x, y, width, height).
>> I think that API is easier to understand (if a little clumsier in
>> practice) than Image.crop(xstart, ystart, xend, yend).
>>
>> If I recall correctly, we also decided to avoid using square brackets
>> in the API, which makes consistency with list[], a bit less important.
>>
>> If you do need a range, however, it should definitely be left-closed,
>> right-open.
> 
> Consistency with Python slicing is not important, perhaps, but
> microbit.random(x) returns a number [0, x), and of course we have
> range(x) iterating over the interval [0, x).  It's all over the place in
> Python, and it's snuck into MicroPython too, and I just wanted to
> confirm that we had our story straight and we weren't trying to hide
> this detail from the kids for fear of confusing them.
> 
> I thought I remembered a conversation where we said "ranges should
> include both endpoints as that's less confusing for kids".  But it
> sounds like we're all in agreement: it should all be left-closed
> right-open intervals.  (Anyway, surely it'd be /more/ confusing if some
> functions took left-closed right-open intervals and others took closed
> intervals?)
> 
> My accelerator-scaler device takes two ranges: the start & end for the
> input (from the accelerometer), and the start & end for the output (what
> will be returned).  Therefore this:
>     scaler = microbit.game.Scaler(-512, 512, 0, 5)
> should say "take the input from [512, 512) and map it to the range [0,
> 5)".  As in, it will ignore inputs less than -512 and greater than 511,
> and will return 0, 1, 2, 3, or 4, but never -1 or 5.
> 
> 
> Yes?  Your lack of reply will be interpreted as silent assent.
> 
> 
> //arry/
> 
> p.s. (x, y, width, height) is pretty common for image APIs.  You see
> (xstart, ystart, xend, yend) now and then too but it's less common.  And
> yes I generally prefer the former.
> 
> 
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <https://mail.python.org/mailman/private/microbit/attachments/20151012/73966276/attachment.sig>


More information about the Microbit mailing list