Commit 3a5d204db17b0681cb97efe5ac84a6d5db16644c

Authored by Geoffrey Challen
1 parent 08f18b2b

New.

Showing 1 changed file with 24 additions and 32 deletions
maybe.tex
@@ -3,8 +3,8 @@ @@ -3,8 +3,8 @@
3 3
4 To begin we provide an overview of the \texttt{maybe} statements semantics, 4 To begin we provide an overview of the \texttt{maybe} statements semantics,
5 describing how it structures uncertainty in variable values and runtime 5 describing how it structures uncertainty in variable values and runtime
6 -execution. We refer to each of the values a \texttt{maybe} variable can take  
7 -or paths a \texttt{maybe} code block can execute as an \textit{alternative}. 6 +execution. We refer to each of the values or code paths a \texttt{maybe}
  7 +statement can choose from as an \textit{alternative}.
8 8
9 \begin{figure}[t] 9 \begin{figure}[t]
10 \begin{minted}[fontsize=\footnotesize]{java} 10 \begin{minted}[fontsize=\footnotesize]{java}
@@ -22,23 +22,18 @@ int myFunction(int a) { /* Second alternative */ } @@ -22,23 +22,18 @@ int myFunction(int a) { /* Second alternative */ }
22 // Inlining evaluation code 22 // Inlining evaluation code
23 maybe { 23 maybe {
24 ret = fastPowerHungryAlgorithm(input); 24 ret = fastPowerHungryAlgorithm(input);
25 - choice = FAST;  
26 } or { 25 } or {
27 ret = slowPowerEfficientAlgorithm(input); 26 ret = slowPowerEfficientAlgorithm(input);
28 - choice = SLOW;  
29 } analyze { 27 } analyze {
30 return { "repeat": false, 28 return { "repeat": false,
31 "score" : nanoTime() + powerDrain() } 29 "score" : nanoTime() + powerDrain() }
32 } 30 }
33 31
34 -// Cleanup may depend on which algorithm was used  
35 -if(choice == FAST){ cleanUpAfterFastAlg(ret); }  
36 -else { cleanUpAfterSlowAlg(ret); }  
37 \end{minted} 32 \end{minted}
38 33
39 \vspace*{-0.2in} 34 \vspace*{-0.2in}
40 35
41 -\caption{\textbf{More Examples of \texttt{maybe} Statements.}} 36 +\caption{\textbf{More \texttt{maybe} Statements}}
42 37
43 \label{fig-maybeexamples} 38 \label{fig-maybeexamples}
44 39
@@ -70,36 +65,33 @@ or reorganize logic that does not affect correctness, but may (or @@ -70,36 +65,33 @@ or reorganize logic that does not affect correctness, but may (or
70 may not) improve performance if executed. 65 may not) improve performance if executed.
71 66
72 Figure~\ref{fig-maybeexamples} shows several extensions of the \texttt{maybe} 67 Figure~\ref{fig-maybeexamples} shows several extensions of the \texttt{maybe}
73 -statement providing syntactic sugar. \texttt{maybe} function annotations allow  
74 -uncertainty to be expressed at the function level, with the alternatives  
75 -consisting of multiple function definitions with identical signatures. Finally,  
76 -\texttt{maybe} blocks that require special performance evaluation logic can  
77 -include that in the form of a \texttt{better} statement following the main  
78 -\texttt{maybe}  
79 -block, as shown in the final example. \texttt{better} blocks provide  
80 -application-specific logic that performs a post-mortem on the selected  
81 -execution path. The \texttt{better} block must return a  
82 -single JSON object that includes two components: A score, with smaller being  
83 -interpreted as better; and a boolean indicating whether the system should  
84 -use the same branch next time, or if it is free to try another.  
85 -Note that hints and dedicated evaluation logic can also be  
86 -applied to variable and function-level \texttt{maybe} statements through  
87 -annotations.  
88 -We will return to post-mortem evaluation  
89 -in Section~\ref{sec-certainty}. 68 +statement providing syntactic sugar. \texttt{maybe} function annotations
  69 +allow uncertainty to be expressed at the function level, with the
  70 +alternatives consisting of multiple function definitions with identical
  71 +signatures. Finally, \texttt{maybe} blocks that require special performance
  72 +evaluation logic can include that in the form of a \texttt{better} statement
  73 +following the main \texttt{maybe} block, as shown in the final example.
  74 +\texttt{better} blocks provide application-specific logic that analyze the
  75 +selected execution path. The \texttt{better} block must return a single JSON
  76 +object that includes two components: A score, with smaller being interpreted
  77 +as better; and a boolean indicating whether the system should use the same
  78 +branch next time, or if it is free to try another. Note that hints and
  79 +dedicated evaluation logic can also be applied to variable and function-level
  80 +\texttt{maybe} statements through annotations. We will return to post-mortem
  81 +evaluation in Section~\ref{sec-certainty}.
90 82
91 \subsection{Discussion} 83 \subsection{Discussion}
92 84
93 -We have yet to determine how well programmers will be able to use the new  
94 -\texttt{maybe} construct. At some level, \texttt{maybe} statements are  
95 -similar to the common \texttt{if-else} construct in that at the bottom of the 85 +We have yet to determine how well programmers will be able to use the
  86 +\texttt{maybe} statement. Structurally \texttt{maybe} statements are similar
  87 +to the common \texttt{if-else} construct in that at the bottom of the
96 statement the programmer may not be sure which block was executed. However, 88 statement the programmer may not be sure which block was executed. However,
97 while with \texttt{if-else} blocks it can be determined which block was 89 while with \texttt{if-else} blocks it can be determined which block was
98 executed by examining the branch conditions, \texttt{maybe} statements 90 executed by examining the branch conditions, \texttt{maybe} statements
99 -require developers record which alternative was used if downstream code  
100 -depends on the decision. Alternatively, programmers may use a \texttt{maybe}  
101 -variable to select a policy and employ traditional \texttt{if-else}  
102 -statements to direct control flow based on the \texttt{maybe} variable. 91 +require developers record which alternative was executed if downstream code
  92 +depends on the decision. To coordinate the adaptation of multiple code paths
  93 +a single \texttt{maybe} variable can be used to control multiple
  94 +\texttt{if-else} statements.
103 95
104 While \texttt{maybe} is a powerful programming tool, it is important that it 96 While \texttt{maybe} is a powerful programming tool, it is important that it
105 be used sparingly. In the case where dependencies exist between the 97 be used sparingly. In the case where dependencies exist between the