Commit e19a7e8649b99de4e7728b9799b839332fe0a7fa
1 parent
9330201e
Cleanup.
Showing
3 changed files
with
76 additions
and
79 deletions
introduction.tex
| 1 | \section{Introduction} | 1 | \section{Introduction} |
| 2 | 2 | ||
| 3 | -All programmers must deal with uncertainty about runtime environments. | ||
| 4 | -For example, the most appropriate algorithm for a given task may | ||
| 5 | -depend on inputs | ||
| 6 | -that are unknown when the function is written, and its performance may | ||
| 7 | -depend on device-specific features that are impossible for the developer to | 3 | +All programmers must deal with uncertainty about runtime environments. For |
| 4 | +example, the most appropriate algorithm for a given task may depend on inputs | ||
| 5 | +that are unknown when the function is written, and its performance may depend | ||
| 6 | +on device-specific features that are impossible for the developer to | ||
| 8 | anticipate. In other cases, real-world testing may be required to choose | 7 | anticipate. In other cases, real-world testing may be required to choose |
| 9 | -between several approaches; This has led to the popularity of so-called AB | ||
| 10 | -or split testing. | ||
| 11 | - | ||
| 12 | -Uncertainty is especially problematic for mobile app programmers: | ||
| 13 | -Specific device features, such as | ||
| 14 | -accurate location from GPS, may or may not be available. Networks come and go, | ||
| 15 | -and their properties may change, from fast and free Wifi links to slower or | ||
| 16 | -metered mobile data connections. Energy may be plentiful or nearly exhausted, | ||
| 17 | -depending on the device's battery capacity and the user's energy consumption | ||
| 18 | -and charging patterns. These constantly fluctuating exogenous conditions | ||
| 19 | -make writing effective mobile apps particularly challenging. | ||
| 20 | - | ||
| 21 | -The most typical approach to address this problem is to force the | ||
| 22 | -programmer to implement the required adaptation themselves. | 8 | +between several approaches, which has led to the popularity of split testing. |
| 9 | + | ||
| 10 | +Uncertainty is especially problematic for mobile app programmers. Specific | ||
| 11 | +device features, such as accurate GPS location, may or may not be available. | ||
| 12 | +Networks come and go and their properties change: from fast and free Wifi | ||
| 13 | +links to slower metered mobile data connections. Energy may be plentiful or | ||
| 14 | +scarce, depending on the device's battery capacity and the user's energy | ||
| 15 | +consumption and charging patterns. These constantly fluctuating exogenous | ||
| 16 | +conditions make writing effective mobile apps particularly challenging. | ||
| 17 | + | ||
| 18 | +Today programmers are forced to anticipate these changing conditions at | ||
| 19 | +development time and implement the required adaptation themselves. | ||
| 23 | Figure~\ref{fig-example-if} shows an example of an Android app attempting to | 20 | Figure~\ref{fig-example-if} shows an example of an Android app attempting to |
| 24 | adapt to the device's battery level by establishing regular- and low-battery | 21 | adapt to the device's battery level by establishing regular- and low-battery |
| 25 | -code paths, with the latter attempting to save energy---by utilizing a slower | ||
| 26 | -but more energy-efficient algorithm, computing an approximation instead of an | ||
| 27 | -exact result, or deferring the computation. | ||
| 28 | - | ||
| 29 | -\sloppypar{ Unfortunately, this approach has several serious weaknesses. The | ||
| 30 | -most important is perhaps the least obvious: It is unclear that the | ||
| 31 | -different code paths achieve the desired result. There may be no differences | ||
| 32 | -between the alternatives (neither conserves energy), the alternative | ||
| 33 | -designed to conserve energy may actually consume more due to bugs or | ||
| 34 | -incorrect assumptions, or the result may also depend on some other factor not | ||
| 35 | -considered by the programmer, such as the type of network the device is | ||
| 36 | -connected to.} | 22 | +code paths, with the latter attempting to save energy, possibly by utilizing |
| 23 | +a slower but more energy-efficient algorithm, computing an approximate | ||
| 24 | +result, or deferring the computation. | ||
| 25 | + | ||
| 26 | +Unfortunately, this approach has several serious weaknesses. The most | ||
| 27 | +important is perhaps the least obvious: it is unclear that the different code | ||
| 28 | +paths achieve the desired result. There may be no differences between the | ||
| 29 | +alternatives (neither conserves energy), the alternative designed to conserve | ||
| 30 | +energy may actually consume more due to bugs or incorrect assumptions, or the | ||
| 31 | +result may also depend on some other factor not considered by the programmer, | ||
| 32 | +such as the type of network the device is currently using. | ||
| 37 | 33 | ||
| 38 | In addition, adaptive programming frequently requires arbitrary decision | 34 | In addition, adaptive programming frequently requires arbitrary decision |
| 39 | thresholds chosen before deployment. Even if the two code paths shown in | 35 | thresholds chosen before deployment. Even if the two code paths shown in |
| @@ -51,15 +47,15 @@ if (plugged == false && batteryLevel < 10) { | @@ -51,15 +47,15 @@ if (plugged == false && batteryLevel < 10) { | ||
| 51 | } | 47 | } |
| 52 | \end{minted} | 48 | \end{minted} |
| 53 | 49 | ||
| 54 | -\vspace*{-0.2in} | 50 | +\vspace*{-0.1in} |
| 55 | 51 | ||
| 56 | -\caption{\textbf{Typical Error-prone Energy Adaptation.} The threshold is | ||
| 57 | -arbitrary and the attempt to conserve energy may not work sometimes, for some | ||
| 58 | -users, or at all.} | 52 | +\caption{\textbf{Typical Error-Prone Energy Adaptation.} The threshold is |
| 53 | +arbitrary and the attempt to conserve energy succeed only at certain times, | ||
| 54 | +only for certain users, only on certain devices, or never.} | ||
| 59 | 55 | ||
| 60 | \label{fig-example-if} | 56 | \label{fig-example-if} |
| 61 | 57 | ||
| 62 | -\vspace*{-0.2in} | 58 | +\vspace*{-0.1in} |
| 63 | 59 | ||
| 64 | \end{figure} | 60 | \end{figure} |
| 65 | 61 | ||
| @@ -70,14 +66,14 @@ these common tasks require writing large amounts of error-prone boilerplate | @@ -70,14 +66,14 @@ these common tasks require writing large amounts of error-prone boilerplate | ||
| 70 | code, including APIs to adjust values at runtime and code to retrieve | 66 | code, including APIs to adjust values at runtime and code to retrieve |
| 71 | settings from remote servers. | 67 | settings from remote servers. |
| 72 | 68 | ||
| 73 | -The root of the problem is that when it comes to the scope and effects of | ||
| 74 | -exogenous runtime conditions, \textbf{today's languages force programmers | ||
| 75 | -to be certain at a moment when they cannot be}, at compile time. | ||
| 76 | -This weakness is only exacerbated by the amount of variation across different | ||
| 77 | -mobile devices. Our solution is simple: (1) Provide developers with a | ||
| 78 | -way to express structured uncertainty as sets of equivalent options, | ||
| 79 | -and (2) Use this structure to enable a robust array of downstream tools for | ||
| 80 | -resolving uncertainty by selecting among options provided by the developer. | 69 | +The root of the problem is that \textbf{today's languages force programmers to |
| 70 | +be certain at a moment when they cannot be}: at development time. While this | ||
| 71 | +problem is endemic to existing programming languages, when developing mobile | ||
| 72 | +apps it is magnified by the amount of variation developers must confront. Our | ||
| 73 | +solution is simple: (1) provide developers with a way to express | ||
| 74 | +\textit{structured uncertainty}, and (2) use the resulting flexibility to | ||
| 75 | +enable a large array of downstream tools for resolving uncertainty by | ||
| 76 | +choosing from the alternatives provided by the developer. | ||
| 81 | 77 | ||
| 82 | \begin{figure}[t] | 78 | \begin{figure}[t] |
| 83 | 79 | ||
| @@ -91,31 +87,30 @@ maybe { | @@ -91,31 +87,30 @@ maybe { | ||
| 91 | 87 | ||
| 92 | \vspace*{-0.2in} | 88 | \vspace*{-0.2in} |
| 93 | 89 | ||
| 94 | -\caption{\textbf{Example Use of the \texttt{maybe} Statement.} } | 90 | +\caption{\textbf{Example \texttt{maybe} Statement}} |
| 95 | \label{fig-example-maybe} | 91 | \label{fig-example-maybe} |
| 96 | 92 | ||
| 97 | \vspace*{-0.2in} | 93 | \vspace*{-0.2in} |
| 98 | 94 | ||
| 99 | \end{figure} | 95 | \end{figure} |
| 100 | 96 | ||
| 101 | -In this paper, we focus on the challenge of providing developers with | ||
| 102 | -a language construct for expressing structured uncertainty: The | ||
| 103 | -\texttt{maybe} statement. \texttt{maybe} statements allow programmers to | ||
| 104 | -express sets of equivalent options for both data and control-flow. | ||
| 105 | -Figure~\ref{fig-example-maybe} shows a simple case of a \texttt{maybe} case | ||
| 106 | -statement applied to our earlier example. Instead of being forced to choose, | ||
| 107 | -being forced to attempt to implement the decision process, or even required | ||
| 108 | -to evaluate multiple options, the programmer is free to offer two or more | ||
| 109 | -alternatives that are different but both correct, although one may be | ||
| 110 | -preferable. At runtime only one will be used during any given execution, with | ||
| 111 | -the system choosing the alternative that saves energy when it is appropriate | ||
| 112 | -to do so. Note that the branch that a \texttt{maybe} statement takes | ||
| 113 | -is not random; Rather, it tries to make the best choice and not just any choice. | 97 | +In this paper, we present a novel a language construct for expressing |
| 98 | +structured uncertainty: the \texttt{maybe} statement. \texttt{maybe} | ||
| 99 | +statements allow programmers to express sets of equivalent alternatives for | ||
| 100 | +both data and control-flow. Figure~\ref{fig-example-maybe} shows a simple | ||
| 101 | +case of a \texttt{maybe} case statement applied to our earlier example. | ||
| 102 | +Instead of being forced to choose, being forced to attempt to implement the | ||
| 103 | +decision process, or even required to evaluate multiple alternatives, the | ||
| 104 | +programmer is free to offer two or more alternatives that are different but | ||
| 105 | +both correct, although one may be preferable. At runtime only one will be | ||
| 106 | +used during any given execution, with the system both determining the energy | ||
| 107 | +tradeoffs produced by multiple alternatives and activating energy-saving | ||
| 108 | +alternatives when appropriate. | ||
| 114 | 109 | ||
| 115 | How that choice is made is discussed in the remainder of our paper. We begin | 110 | How that choice is made is discussed in the remainder of our paper. We begin |
| 116 | by providing a more complete description of the \texttt{maybe} statement in | 111 | by providing a more complete description of the \texttt{maybe} statement in |
| 117 | -Section~\ref{sec-maybe}. Section~\ref{sec-certainty} describes several | ||
| 118 | -techniques for collapsing compile-time uncertainty into the required runtime | ||
| 119 | -certainty. We continue by | ||
| 120 | -briefly describing several example use cases in Section~\ref{sec-usage} and related work in Section~\ref{sec-related}. | ||
| 121 | -We conclude in Section~\ref{sec-conclusion}. | 112 | +Section~\ref{sec-maybe}. Section~\ref{sec-certainty} describes several |
| 113 | +techniques for collapsing compile-time uncertainty into the required runtime | ||
| 114 | +certainty. We continue by briefly describing several example use cases in | ||
| 115 | +Section~\ref{sec-usage} and related work in Section~\ref{sec-related}. We | ||
| 116 | +conclude in Section~\ref{sec-conclusion}. |
maybe.tex
| 1 | \section{\texttt{\large maybe} Statement Semantics} | 1 | \section{\texttt{\large maybe} Statement Semantics} |
| 2 | \label{sec-maybe} | 2 | \label{sec-maybe} |
| 3 | 3 | ||
| 4 | -\sloppypar{To begin, we provide a brief overview of the semantics of the | ||
| 5 | -\texttt{maybe} statement, describing how it can express structured | ||
| 6 | -uncertainty in variable values and runtime execution. We refer to each of the | ||
| 7 | -values a \texttt{maybe} variable can take and each of the a paths a | ||
| 8 | -\texttt{maybe} code block can execute as an \textit{alternative}. | 4 | +To begin, we provide a brief overview of the semantics of the \texttt{maybe} |
| 5 | +statement, describing how it can express structured uncertainty in variable | ||
| 6 | +values and runtime execution. We refer to each of the values a \texttt{maybe} | ||
| 7 | +variable can take and each of the a paths a \texttt{maybe} code block can | ||
| 8 | +execute as an \textit{alternative}. | ||
| 9 | + | ||
| 10 | +Note that structured uncertainty is not randomness. The \texttt{maybe} | ||
| 11 | +statement indicates that during any given execution one alternative may be | ||
| 12 | +better than the others---even if the developer or system are not sure which | ||
| 13 | +alternative to use. | ||
| 9 | 14 | ||
| 10 | \begin{figure}[t] | 15 | \begin{figure}[t] |
| 11 | \begin{minted}[fontsize=\footnotesize]{java} | 16 | \begin{minted}[fontsize=\footnotesize]{java} |
| @@ -51,17 +56,10 @@ else { cleanUpAfterSlowAlg(ret); } | @@ -51,17 +56,10 @@ else { cleanUpAfterSlowAlg(ret); } | ||
| 51 | 56 | ||
| 52 | Variables can be used to represent uncertainty. Examples include an integer | 57 | Variables can be used to represent uncertainty. Examples include an integer |
| 53 | storing how often a timer should trigger communication with a remote server, | 58 | storing how often a timer should trigger communication with a remote server, |
| 54 | -or a string containing the name of a policy used to coordinate multiple | ||
| 55 | -code blocks through the app. | ||
| 56 | -% Note that at present the \texttt{maybe} | ||
| 57 | -% statement controlling code blocks described below does not include features | ||
| 58 | -% required to coordinate multiple code blocks, and so if this functionality is | ||
| 59 | -% required, multiple \texttt{if-else} statements branching on a | ||
| 60 | -%\texttt{maybe}-derived variable can be used. | ||
| 61 | -Figure~\ref{fig-maybeexamples} | ||
| 62 | -shows examples of an integer that can take on values between 1 and 16, and a | ||
| 63 | -string that be set to either ``auto'', ``quality'', or ``perf''. | ||
| 64 | -A s | 59 | +or a string containing the name of a policy used to coordinate multiple code |
| 60 | +blocks through the app. Figure~\ref{fig-maybeexamples} shows examples of an | ||
| 61 | +integer that can take on values between 1 and 16, and a string that be set to | ||
| 62 | +either ``auto'', ``quality'', or ``perf''. | ||
| 65 | 63 | ||
| 66 | \subsection{Controlling Code Flow} | 64 | \subsection{Controlling Code Flow} |
| 67 | 65 |