PythonEditor
PythonEditor copied to clipboard
blocks: how to handle 'undocked' blocks
(this is a complex one that I think needs some discussion - opening this issue as a place for that)
At the moment in blocks, as far as I can see, any block on the canvas will cause code to be generated and likely run. There aren't 'hats' or 'events', not even an 'on start' one.
This can cause a few possible issues.
For one, it's fundamentally different to scratch
In this case, the 'hmm' will never happen.
The difference is not in itself a reason to change, but In the past we've seen kids use 'undocking' blocks as a way to 'comment them out' (IE you build a complex set of blocks and then 'undock' them in order to stop them running. This is one good reason to think about how things work.
(it's also different from PXT, too)
Secondly, it can create some confusing things on canvas if your project has grown and then shrunk again.
For example, someone who knows how to code will easily spot the issue here:
...but for someone who is only focused on the blocks this could be really confusing. This is a slightly artificial example, but I think the problem in general is real, especially given the lack of clear notification that things are not currently visible, etc. (see in part #42 )
Note that PXT removed 'hats' early on in development and decided to add them back. There's a good discussion about that here: https://github.com/Microsoft/pxt/issues/849
I can't recreate the situation you have in the second screenie. If I remove the "reset" block, the reset() code is removed. Furthermore, if I reorder the vertical order of blocks this is reflected in the order of the lines in the Python code.
Hats are a bad idea. Once again, Python is different to PXT, Scratch, we should celebrate such differences and encourage people to explore... yadda yadda yadda. ;-)
Can you please substantiate "hats are a bad idea"? I've given at least two example above of why they're a good idea.
The point of the second screenshot is that you can't see the reset block, it's offscreen but totally interfering with what looks like the program.
It should read, "hats are a bad idea in Python". Why? Because, as far as I can tell, there's no equivalent to hats in Python, so we're making stuff up. If you scroll a block off the screen, I'd argue that's your problem rather than Python's. Perhaps we should add a button to remove all code created by blocks that are not visible to mitigate the problematic situation you've created..?
I think in Python there's exactly one hat, no? "When program starts"?
By adding that hat, we'd get the ability to have 'undocked' blocks used for commending out code, and also a bit more clarity for kids about what will run and in what order.
Downside: I guess it means you don't get to use the canvas as freely but because we don't have functions (yet ;) ?) and using the canvas freely leads to the odd situation I showed, I think that's actually a down-up-side.
The event-less model of Python lends itself to game loops, etc, but I think requiring things to be docked into these might really help?
Aha... OK I see what you mean. I guess this is another UX-y type investigation.
Regarding function - it ain't going to happen in blocks. If you know you need functions, you're advanced enough to type Python. ;-)