Skip to content
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

Implement anonymous procedure & multi-thread blocks #1565

Open
wants to merge 45 commits into
base: ucr
Choose a base branch
from

Conversation

ColinTree
Copy link
Contributor

@ColinTree ColinTree commented Feb 15, 2019

This PR implements anonymous procedure defining and calling. As suggested by @wxbit, name anonymous procedure is avoid to be displayed in these blocks, in order to avoid increasing learning costs.
What's more, blocks get procedure & calling procedure with input list are suggested by @wxbit. (Thank you!)

With anonymous procedure introduced into appinventor, callbacks can now be defined and implementing multi-thread blocks can be added into the plan.

Need help/suggestion:

  • TOOLTIPs
  • HELPURLs
  • type blocks
  • order of blocks
  • block naming

Blocks added (in control)

image

(in category procedure):

image

Some samples:

  • calling a global defined procedure
    image

  • Calculating with mode switcher
    image

  • Calculating with mode switcher (2)
    image

@wxbit
Copy link
Contributor

wxbit commented Feb 15, 2019

Amazing! 👍

@wxbit
Copy link
Contributor

wxbit commented Feb 15, 2019

I suggest rename "get global procedure" to "get procedure".

@ColinTree ColinTree marked this pull request as ready for review February 17, 2019 07:17
@ColinTree ColinTree changed the title Implement anonymous procedure Implement anonymous procedure & multi-thread blocks Feb 17, 2019
@ewpatton
Copy link
Member

@ColinTree Rather than having the "get procedure" block take a name parameter, why not provide a dropdown similar to the call blocks? This would allow us to adjust the function reference when the developer renames a procedure.

@ewpatton
Copy link
Member

Also, because this adds behavior to the companion, the base branch should be ucr, not master.

@wxbit
Copy link
Contributor

wxbit commented Feb 17, 2019

A name parameter can be called at runtime.

@ewpatton
Copy link
Member

Computed, maybe? name is a string, and strings are not callable. In any case, all named procedures will be known at compile time, so I think it makes sense to constrain it accordingly in the blocks.

@wxbit
Copy link
Contributor

wxbit commented Feb 18, 2019

Sometimes you need to define a series of procedure, the block allows you to decide which one to call based on user input or action.

@ColinTree
Copy link
Contributor Author

You can determine the procedure name that you want to call in runtime, e.g. specified by config from your server during runtime.

@ColinTree
Copy link
Contributor Author

@ewpatton Thanks for your reply!

In my opinion, avoid programming mistakes should be the responsibility of developers, designers like us should put more focus on adding more and more possibilities & functionalities into the platform/language.

But I can see your concern is very reasonable, that many of App Inventor users (developers) are still new for programming. So one solution of this should be adding one more block that has a dropdown of defined procedure names and current existing blocks are still kept for them to choose.

What do you think?

@ewpatton
Copy link
Member

Language designers can't protect developers from logical mistakes, true, but there are certainly plenty of ways in which we can reduce other types of mistakes. For example, this is why some languages have garbage collectors (Java) to prevent memory leaks due to malloc/free mismatches, or memory safety (Rust) to prevent buffer overflow attacks. Look to how variable renaming in App Inventor works as a good example of how we prevent mistakes when it comes to referencing items by name. When you rename a variable, all of its references are renamed at the same time. This doesn't allow one to accidentally decouple the reference from the original definition. I'm simply advocating that we strongly consider that first, and I have given two alternatives approaches that could provide similar flexibility while helping introduce users to the concepts of functional programming in a more guided way.

@ewpatton
Copy link
Member

Also inviting @jsheldonmit @kdclang @stezelMIT to comment from the educational perspective.

@wxbit
Copy link
Contributor

wxbit commented Feb 18, 2019

Average user can use the dropdown box block, dynamically look up procedures by name is an advanced usage for experienced users. The PR bring more possibilities for App Inventor.

@ColinTree
Copy link
Contributor Author

@ewpatton Block getWithDropdown had been added.
image

@kdclang
Copy link

kdclang commented Feb 18, 2019

Agree with @ewpatton that the dropdown is necessary. I would also recommend hiding the more advanced blocks (this might be something we need to address with the planned feature to hide blocks/components) because it could confuse new programmers to see so many blocks under the procedures drawer.

@AppInventorWorkerBee
Copy link
Collaborator

Can one of the admins verify this patch?

@ColinTree ColinTree mentioned this pull request Mar 12, 2019
@mishra-kunal
Copy link
Contributor

@ColinTree how to work with run in background blocks and run after period? Can you show some example , how to use that ? And can you explain about that?
Regards,
Kunal Mishra

@zhangzqs
Copy link

@ColinTree how to work with run in background blocks and run after period? Can you show some example , how to use that ? And can you explain about that?
Regards,
Kunal Mishra

You can put an function start(procedure, time), which puts a run after period block, millis=time, passes in an anonymous function, and calls the start(procedure, time) function to form a recursion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants