Program your own Functions
Thunkable
DragAndDropCode.com, David Wolber
Introducing Programmer-Defined Functions
Your apps have consisted of:
DragAndDropCode.com, David Wolber
Refactoring Code
DragAndDropCode.com, David Wolber
DEMO: Refactoring “Meet My..”
To create a function:
DragAndDropCode.com, David Wolber
Refactoring to eliminate redundancy
when E1
op1
op2
opx
opy
when E2
op1
op2
opa
opb
when E1
when E2
func
call func
call func
opx
opy
op1
op2
opa
opb
DragAndDropCode.com, David Wolber
An Updated Grammar:
DragAndDropCode.com, David Wolber
How do Functions Help?
when E1
op1
op2
opx
opy
when E2
op1
op2
opa
opb
when E1
when E2
func
call func
call func
opx
opy
op1
op2
opa
opb
DragAndDropCode.com, David Wolber
How do Functions Help?
2. Break down the app into smaller, more manageable chunks
DragAndDropCode.com, David Wolber
Abstraction
Abstraction (short definition):
Give a name to some detailed information.
“Brush your teeth” analogy
Facilitates communication: at times you and your team can ignore details, at other times dig into them
DragAndDropCode.com, David Wolber
Functional Abstraction
The ability to name and later call a set of instructions like [GenerateNumbers] is one of the key tools in computer science and is referred to as procedural abstraction. It is called abstraction because the caller of the procedure (who, in real-world projects, is likely to be different from the author of the procedure) only needs to know what the procedure does(generate a list), not how it does it (by making calls to the random-number generator, and insert calls). Without procedural abstraction, big computer programs would not be possible, because they contain too much code for one person to hold in his head at a time. This is analogous to the division of labor in the real world, where, for example, different engineers design different parts of a car, none of them understanding all of the details, and the driver only has to understand the interface (e.g., pressing the brake pedal to stop the car), not the implementation.
modified from Ellen Spertus, App Inventor
note: “Procedure” aka “function”
DragAndDropCode.com, David Wolber
Functional Abstraction
Some advantages of procedural abstraction over copying and pasting code are:
From Ellen Spertus, App Inventor
DragAndDropCode.com, David Wolber