-
Notifications
You must be signed in to change notification settings - Fork 288
Add docs / photos describing PyCon UK related discussion on API. #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I think we should not add images to the repo. They make it big (and are always there in the version control). Instead let's just transcribe their content to text. |
A wiki could be used. Right now time is of the essence so we should just use whatever means we can to flesh out the API. Feel free to make a wiki page if you like (It could be used later on for general API reference). I think we also decided that animate would take the "wait" and "loop" keywords. Other functions like print and scroll can also take the "wait" keyword (and even the "loop" keyword makes sense for them). |
I've added the notes here: https://github.com/dpgeorge/microbit-micropython/wiki/API-Design-Heuristics. Pictures are here: https://github.com/dpgeorge/microbit-micropython/wiki/API-Design-Images |
I updated the wiki to reflect new decisions on API. One thing to consider: read_analog / write_analog take/return a number between 0 and 1023. That range is pretty obscure for kids. We can make it an integer between 0 and 100, or even a float between 0 and 1. Any comments? |
I like the idea of using a float between 0.0 and 1.0 for analog values. It matches up with the digital values nicely. |
How familiar are 11 year olds with decimal fractions? I was 11 too long ago to remember :) |
Yes, probably an integer (between 0 and 100) is much easier. |
I vote whole numbers between 0-100 since pretty much all children, no matter their ability level, will understand this. (N.B. When I was a teacher, I'd get 1 or 2 kids out of a 100-ish-person cohort in each year 7 who couldn't count to 100 for various SEN [special educational needs] reasons. Teachers will be aware of who these pupils are and should have strategies in place to deal with this, all coordinated by the school's SENCO [special educational needs co-ordinator] whose task it is to make sure such kids have joined-up and consistent support). |
OK, 0 to 100 it is. I'm going to accept floats as well (in the same range) so that |
Yes, I think this is a good idea. Forcing the kids to do Similarly set_analog_period_microseconds should accept a float and truncate it to an int. See also #7. |
On 09/27/2015 10:48 AM, Damien George wrote:
Just asking: is the range [0..100)? As in, you will see the value 0, (And, did you mean int(3/100)?) //arry/ |
The range is [0..100] with 101 values. |
It is a good question. I think it should be [0..100]. But now that I think more about this range I realise that we lose a lot of precision with an analog return value between 0 and 100. The internal ADC is 10 bit and so 1023 is it's maximum value. I'm pretty sure the device can achieve this resolution and I don't think we should unnecessarily truncate. Options:
|
My 2c as the devil's advocate... although I'm happy to be shot down and concede... ;-) I believe that if there is an input that has a range of possible values we should expose the full range in the simplest form possible. If there are 1024 possible values then I believe that's what we should report. That we can do it with integers is a plus because all children are likely to understand this concept (whereas floats will confuse some of them). To counter the "but 1024 is weird" point: that's only the same as starting to count from 0, but we don't worry about that! Also, as kids become more familiar with programming they will start to encounter such base 2 related numbering and recognise them for what they are. I believe this is simply another way in which we're gently introducing fundamental aspects of computers. (But I concede this is a rather arbitrary position to take - I guess it has more to do with taste and intuition about such things than any hard or fast rule.) It also means we're uniform with TouchDevelop. This is a good thing except for when TouchDevelop is obviously wrong :-) For example, some of TD's names for things are bonkers IMHO - this is a matter of taste about naming things and we have our own heuristics for doing this - KISS, short, easy to spell, commonly used vocabulary, no acronyms etc... In contrast, it's not a matter of taste that analog input has a range of 0-1023 - that's just how it works because of its physical properties. To go all highfalutin - the former is a socially constructed description (i.e. some human has decided some name because they think that's the way it should be), whereas the latter is scientifically derived (we can go check that there is in fact a range of only 1024 possible values one can extract from the pin). If TD "socially constructs" weird names then we should ignore them and do the right thing. If TD exposes a range of 1024 possible values because that's the way the device works, then we should do the same. Does this make sense? |
On 09/27/2015 12:53 PM, Damien George wrote:
Let me paraphrase* Albert Einstein and say: an API should be as simple So let me ask you: what API would /you/ want? That's easy: [0..1) as a
If we really can't do [0..1), in my opinion the only other sensible Actually I think we can improve that slightly: We could even continue to accept floats, so if they have a range from 0 Oh! And then the clever kids (and us) could call //arry /* Apocryphally, at least. ** I'd prefer it be [0..n), as that's enormously more Pythonic. But I |
@larryhastings great stuff! https://www.youtube.com/watch?v=kQFKtI6gn9Y ;-) |
On 09/27/2015 01:42 PM, Larry Hastings wrote:
One more thought. How many kids are going to get as far as noodling //arry/ |
Of course the underlying voltage is the actual physical property being measured and a range of 1024 possible values is somewhat arbitrary, but my devil's advocacy about introducing a familiarity with base 2-ish number still stands. @larryhastings wrt 11yo noodling with analog out - that'll depend a lot on the teacher and how such concepts are introduced. Personally, I think I like 0..1 but I'm not sure how kids would find it. Since I have an 11yo to hand (not immediately, he's asleep upstairs) I could do some subtle testing to see what he and his buddies find easiest. |
We did have a long discussion about this point (ADC return value) for MicroPython proper (see micropython/micropython#1130). In order to be consistent across boards that have different ADC resolutions, and not take the performance hit associated with floating point (and also loss of precision in some cases), the decision was to left shift the result to 16 or 24 bit width, so the maximum would be 0xffff or 0xffffff. Given all of the above, to keep it simple but close to the hardware, go for [0..1024) = [0..1023]. If kids use analog in/out then they'll soon learn what the range means. BTW, analog out should have the same range as in. |
Personally, I'd stick with 0-1023. Thinking process: It's the same then as the other platforms then. Yes, it might seem a little The other thing is that while yes, 1023 is odd, it gives people an excuse As a general principle, I'd just ask when things turn up like this "do we By way of example of something from around 9-10 months back: Co-ordinates So based on comments, the ADC is a 10bit ADC, and that gives arise to 1024 So the questions I'd have is:
My conclusion based on reading the thread is that leaving it unchanged Michael. On 27 September 2015 at 21:30, Nicholas Tollervey notifications@github.com
|
Thanks @sparkslabs that is very useful feedback. We will keep it at 0..1023 (for both analog read and write). It is great to know that there are things like this (and the LED coordinates) that have had a lot of thought and discussion put into them already. We (uPy on the microbit developers) should not try to second guess or re-discuss such things; it's not a good use of time. The problem is we don't know which parts have had discussion and feedback from users. Looking at some parts of the 8000 TD design it seems that not everything is fully thought through, and it's hard to tell which bits are and which are not. If we had a list of API design decisions which have been thoroughly discussed then that would make development go much smoother. |
TD use |
Hmm... I'm not sure... Python has BTW, I'm not sure what the right answer is right now. Intuitively I'd keep |
I think TD originally called it |
Yeah I don't remember. Maybe it's the name that they used in the pilot project a year ago. In any case, sleep is kind of a technical term -- pause actually makes more sense I believe. I think it's ok to have the discrepancy. |
Do we want to be consistent with TD, or with Python--and the entire rest of the world? I vote for the latter and leave it as sleep(). |
We used "pause" in the prototype we used in schools in January (cf http://bug.iotoy.org/bug/create_program/) . I don't recall there being a big discussion about it TBH. Pause in my The prototype slept a lot to conserve power - to the extent that the main for i in 0..4: There was an item in the backlog (never gotten to :-) - to expose the Anyway, I digress. Pause seemed more appropriate than sleep in the context
We documented the sleeping behaviour here: You'll see what I mean. When you have that concept of sleep - which on an embedded device can I don't have strong feelings either way about it, but if I was going to Michael. On 29 September 2015 at 16:50, Jonathan Protzenko notifications@github.com
|
To larry's point, if this is valid in micropython on micro:bit: import time Then I would suggest that that sleep operates the same as Michael On 29 September 2015 at 17:14, Michael sparks.m@gmail.com wrote:
|
I'm with Larry - MicroPython is a version of Python and we should remain consistent within the wider Python ecosystem. I realise this is a question of taste. :-) |
FWIW The DAL has a sleep function, but no pause. |
In this case I consider whether or not the devices does a low-power sleep during a sleep/pause call an implementation issue that doesn't need to concern the user (well not usually). To support proper MCU sleeping requires a method to wake, usually by an real-time-clock alarm interrupt, or external pin interrupt, and I don't expect these details to be exposed in our child-friendly API. So we should think more about the indented meaning of sleep/pause/delay rather than how it's implemented. "Pause" has connotations of pressing pause on a video player or remote control, where everything stops until you press play/continue. I don't think that's what we want, because background animations/music can continue. Instead the device is "waiting", most likely to give the user time to interact (eg read the display). So microbit.wait() might be the right word, but that's breaking with tradition, so microbit.sleep() is also ok. |
@mark - FWIW, I have no strong feelings either way. I was just explaining pause(time) had the same effect as python's time.sleep - but took the That's however a historical artefact and only mildly interesting. As mentio
B9E6
ned, I don't have strong feelings about this since, esp given Michael. On 29 September 2015 at 20:48, Mark Shannon notifications@github.com
|
Given the original content associated with this ticket is now in the Wiki and now that we appear to have a consensus about Happy to re-open if need be but I don't expect to. |
This PR still needs work and contributions before we forget it all.
I suggest we leave this open only 24h so we give people a chance to revise yet we make progress quickly. I'm anxious we don't stymie @whaleygeek's efforts with an ever changing API.