From 3a5d204db17b0681cb97efe5ac84a6d5db16644c Mon Sep 17 00:00:00 2001 From: Geoffrey Challen Date: Mon, 22 Dec 2014 12:10:09 -0500 Subject: [PATCH] New. --- maybe.tex | 56 ++++++++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/maybe.tex b/maybe.tex index 1e4e6b7..6d36c2a 100644 --- a/maybe.tex +++ b/maybe.tex @@ -3,8 +3,8 @@ To begin we provide an overview of the \texttt{maybe} statements semantics, describing how it structures uncertainty in variable values and runtime -execution. We refer to each of the values a \texttt{maybe} variable can take -or paths a \texttt{maybe} code block can execute as an \textit{alternative}. +execution. We refer to each of the values or code paths a \texttt{maybe} +statement can choose from as an \textit{alternative}. \begin{figure}[t] \begin{minted}[fontsize=\footnotesize]{java} @@ -22,23 +22,18 @@ int myFunction(int a) { /* Second alternative */ } // Inlining evaluation code maybe { ret = fastPowerHungryAlgorithm(input); - choice = FAST; } or { ret = slowPowerEfficientAlgorithm(input); - choice = SLOW; } analyze { return { "repeat": false, "score" : nanoTime() + powerDrain() } } -// Cleanup may depend on which algorithm was used -if(choice == FAST){ cleanUpAfterFastAlg(ret); } -else { cleanUpAfterSlowAlg(ret); } \end{minted} \vspace*{-0.2in} -\caption{\textbf{More Examples of \texttt{maybe} Statements.}} +\caption{\textbf{More \texttt{maybe} Statements}} \label{fig-maybeexamples} @@ -70,36 +65,33 @@ or reorganize logic that does not affect correctness, but may (or may not) improve performance if executed. Figure~\ref{fig-maybeexamples} shows several extensions of the \texttt{maybe} -statement providing syntactic sugar. \texttt{maybe} function annotations allow -uncertainty to be expressed at the function level, with the alternatives -consisting of multiple function definitions with identical signatures. Finally, -\texttt{maybe} blocks that require special performance evaluation logic can -include that in the form of a \texttt{better} statement following the main -\texttt{maybe} -block, as shown in the final example. \texttt{better} blocks provide -application-specific logic that performs a post-mortem on the selected -execution path. The \texttt{better} block must return a -single JSON object that includes two components: A score, with smaller being -interpreted as better; and a boolean indicating whether the system should -use the same branch next time, or if it is free to try another. -Note that hints and dedicated evaluation logic can also be -applied to variable and function-level \texttt{maybe} statements through -annotations. -We will return to post-mortem evaluation -in Section~\ref{sec-certainty}. +statement providing syntactic sugar. \texttt{maybe} function annotations +allow uncertainty to be expressed at the function level, with the +alternatives consisting of multiple function definitions with identical +signatures. Finally, \texttt{maybe} blocks that require special performance +evaluation logic can include that in the form of a \texttt{better} statement +following the main \texttt{maybe} block, as shown in the final example. +\texttt{better} blocks provide application-specific logic that analyze the +selected execution path. The \texttt{better} block must return a single JSON +object that includes two components: A score, with smaller being interpreted +as better; and a boolean indicating whether the system should use the same +branch next time, or if it is free to try another. Note that hints and +dedicated evaluation logic can also be applied to variable and function-level +\texttt{maybe} statements through annotations. We will return to post-mortem +evaluation in Section~\ref{sec-certainty}. \subsection{Discussion} -We have yet to determine how well programmers will be able to use the new -\texttt{maybe} construct. At some level, \texttt{maybe} statements are -similar to the common \texttt{if-else} construct in that at the bottom of the +We have yet to determine how well programmers will be able to use the +\texttt{maybe} statement. Structurally \texttt{maybe} statements are similar +to the common \texttt{if-else} construct in that at the bottom of the statement the programmer may not be sure which block was executed. However, while with \texttt{if-else} blocks it can be determined which block was executed by examining the branch conditions, \texttt{maybe} statements -require developers record which alternative was used if downstream code -depends on the decision. Alternatively, programmers may use a \texttt{maybe} -variable to select a policy and employ traditional \texttt{if-else} -statements to direct control flow based on the \texttt{maybe} variable. +require developers record which alternative was executed if downstream code +depends on the decision. To coordinate the adaptation of multiple code paths +a single \texttt{maybe} variable can be used to control multiple +\texttt{if-else} statements. While \texttt{maybe} is a powerful programming tool, it is important that it be used sparingly. In the case where dependencies exist between the -- libgit2 0.22.2