PythonEditor
PythonEditor copied to clipboard
blocks: no warnings when connecting 'incompatible' blocks
(This one probably isn't trivial, as I think it's partially a blockly/Python limitation)
One of the things that blocks is quite good at is avoid syntax errors.
However, our current implementation doesn't protect the user from type error as well as it could.
For example, the following code fails as soon as it is run on the micro:bit

PXT gives slightly more useful feedback:

Do we have a way of giving more immediate feedback to users about type mismatches? Or even better, perhaps (although it's spooky action at a distance) automatically inserting the required conversion so it 'just works'?
As you point out, Python is a dynamically typed language so you need to develop an awareness of these sorts of potential mistakes. In fact, I'd argue that understanding that objects have types (and so you can also get type errors) is a good thing. The only way you're going to learn this is if you encounter type errors.
I'm concerned that we're trying to protect learners too much. It's important to let them make mistakes, ask questions, adjust their behaviour and make progress. A good teacher would intentionally let kids encounter such problems since their end goal is programming Python where these things can happen.
Hope this makes sense.
I don't think the issue here is that there are type errors, but that at the moment with Python on the micro:bit discovering them is a frustrating experience.
Encountering and then fixing type errors == good.
Encountering them only when you get code to the micro:bit and it scrolls a line number on the screen == much more frustrating. Especially if there isn't a teacher to help you or the teacher themselves is exploring and learning as the kids are.
So, we could pop the stack here and make an issue around more instantaneous feedback of errors, but I think that the blockly solution of providing error warnings is a good one for the short term...
OK... how about some sort of code checking in the browser. In my minds eye the purpose of the blocks is to produce Python. If the Python code is wrong because of type errors, it should be flagged in the context of the Python code rather than blocks.
However, if display.scroll can work with __repr__ then this particular type error goes away.
Code checking the the browser that then used the blockly 'errors' to flag an issue is perfect, yep! the __repr__ thing is worth noting but I guess needs a bug on the bbcmicrobit/MicroPython repo?
Yeah, a feature request for repr should go in MicroPython's repos.