“So far in this series we have discussed the advantage of Microsoft PowerApps for empowering “citizen developers” to build real, usable, useful mobile apps with little or no coding experience. ”
With a bit of help from Microsoft’s excellent documentation and a vibrant PowerApps community, building an app is no more challenging than assembling IKEA furniture. Possibly much less challenging, because there’s no risk of losing those weird screws that are only used on IKEA products.
But with PowerApps’ simplicity and mostly visual nature comes some limitations, and in this article we discuss a major one: code reuse, or more specifically, the lack thereof.
What Is Code Reuse?
In traditional computer programming, developers often find that they need the program to perform the same set of commands over and over again, sometimes in quite different parts of the program. Rather than coding the same sequence of commands every time they’re needed (and possibly doing it incorrectly in one or more instances), a good programmer will create a function that contains the commands, and simply “call” the function as needed from the main program. This approach provides a couple of advantages:
-
The function works the same way every time it’s called, so there’s no risk of it working one way in one part of the program and a different way in another.
-
A miscoded function would work wrong every time it’s called, but the advantage here is that it needs to be fixed in only one place.
To take an exceedingly simple example, suppose a programmer finds it necessary to repeatedly calculate the arithmetic average of two numbers. The programmer could create a function, which looks something like this (here I use “pseudocode,” not a specific programming language):
function average (arg1, arg2) {
Avg = (arg1 + arg2)/2
return Avg
}
arg1 and arg2 are arguments, or inputs to the function. When the program needs to calculate the average of two numbers, the programmer simply calls the function:
m = 20
n = 10
x = average (m, n)
The variable x now contains the returned value of the function, or 15 in this case.
Code Reuse and PowerApps
As useful and beneficial as code reuse is, it’s conspicuously absent from PowerApps’ capabilities. There are any number of situations where it would come in handy. For example, it is often necessary in mobile apps to display or hide an input field according to the value of a related “on/off” toggle control. Turn the toggle “on” and the field appears, ready for input; turn it off and the field disappears.
With PowerApps, the programmer has to define this functionality explicitly for each field; you can’t code up a “hide/unhide” function and call it when needed. This sort of limitation drives traditional developers batty, and it’s enough to give PowerApps “citizen developers” fits if they have to do it enough times.
So here’s hoping that some future version of PowerApps gives people the option of lifting the visual-programming covers long enough to implement at least some of the standard features of traditional coding, such as code reuse. Far from being overwhelming to non-coders, who would still have the visual-only option, it would give them something to work up to as they gain experience with the platform.
One can dream, right?