6 and finale
[phd-thesis.git] / tvt / tvt.tex
index 540d8fa..838a97c 100644 (file)
@@ -110,7 +110,7 @@ Both web and \gls{IOT} applications are commonly structured into tiers, e.g.\ th
 
 \begin{landscape}
        \begin{figure}
-               \includegraphics[width=.95\linewidth]{arch}
+               \includegraphics[width=.95\linewidth]{archg}
                \caption{%
                        \Gls{PRS} and \gls{PWS} (left) together with \gls{CRS} and \gls{PRS} (right) mapped to the four-tier \gls{IOT} architecture.
                        Every box is the diagram denotes a source file or base.
@@ -138,7 +138,7 @@ structure complex software is a common software engineering practice that provid
 However, a tiered architecture poses significant challenges for developers of \gls{IOT} and other software. The tiered \gls{PYTHON} \gls{PRS} and \gls{PWS} stacks exhibit these challenges, and we analyse these in detail later in the paper.
 
 \begin{description}[style=sameline]
-       \item[Polyglot development] the developer must be fluent in all the languages and components in the stack, known as being a full-stack developer for webapps \citep{mazzei2018full}. That is, the developer must correctly use multiple languages that have different paradigms, i.e.\ manage significant \emph{semantic friction} \citep{ireland2009classification}. For example the \gls{PWS} developer must integrate components written in seven languages with two paradigms (\cref{sec_t4t:interoperation}).
+       \item[Polyglot development] the developer must be fluent in all the languages and components in the stack, known as being a full-stack developer for webapps \citep{mazzei2018full}. That is, the developer must correctly use multiple languages that have different paradigms, i.e.\ manage significant \emph{semantic friction} \citep{ireland_classification_2009}. For example the \gls{PWS} developer must integrate components written in seven languages with two paradigms (\cref{sec_t4t:interoperation}).
        \item[Correct interoperation] the developer must adhere to the \gls{API} or communication protocols between components. \Cref{sec_t4t:codesize,sec_t4t:resourcerich} show that communication requires some 17\% of \gls{PRS} and \gls{PWS} code, so around 100 \gls{SLOC}. \Cref{sec_t4t:Communication} discusses the complexity of writing this distributed communication code.
        \item[Maintaining type safety] is a key element of the semantic friction encountered in multi-language stacks, and crucial for correctness. The developer must maintain type safety across a range of very different languages and diverse type systems, with minimal tool support. We show an example where \gls{PRS} loses type safety over the network layer (\Cref{sec_t4t:typesafety}).
        \item[Managing multiple failure modes] different components may have different failure modes, and these must be coordinated. \Cref{sec_t4t:NetworkManagement} outlines how \gls{PRS} and \gls{PWS} use heartbeats to manage failures.
@@ -257,7 +257,7 @@ To make this paper self-contained we provide a concise overview of \gls{CLEAN},
 
 \Gls{CLEAN} is a statically typed \gls{FP} language similar to \gls{HASKELL}: both languages are pure and non-strict \citep{achten_clean_2007}.
 A key difference is how state is handled: \gls{HASKELL} typically embeds stateful actions in the \haskellinline{IO} Monad \citep{peyton_jones_imperative_1993,wiki:IO}.
-In contrast, \gls{CLEAN} has a uniqueness type system to ensure the single-threaded use of stateful objects like files and windows \citep{barendsen_smetsers_1996}.
+In contrast, \gls{CLEAN} has a uniqueness type system to ensure the single-threaded use of stateful objects like files and windows \citep{barendsen_uniqueness_1996}.
 Both \gls{CLEAN} and \gls{HASKELL} support fairly similar models of generic programming \citep{ComparingGenericProgramming}, enabling functions to work on many types. As we shall see generic programming is heavily used in task-oriented programming \citep{GenericProgrammingExtensionForClean,HinzeGenericFunctionalProgramming}, for example to construct web editors and communication protocols that work for any user-defined datatype.
 
 \subsection{\texorpdfstring{\Glsxtrlong{TOP}}{Task-oriented programming}}
@@ -312,7 +312,7 @@ readTempTask =
 
 \begin{figure}[ht]
        \centering
-       \begin{subfigure}[t]{.2\textwidth}
+       \begin{subfigure}[c]{.2\textwidth}
                \centering
                \fbox{\includegraphics[width=.9\textwidth]{readTempTask}}
                \caption{Web page.}
@@ -322,7 +322,7 @@ readTempTask =
                \includegraphics[width=\textwidth]{simpleTempSensor}
                \caption{Deployment diagram.}
        \end{subfigure}
-       \caption{\Gls{ITASK} SimpleTempSensor.}%
+       \caption{SimpleTempSensor written in \gls{ITASK}.}%
        \label{fig_t4t:itaskTempSimple}
 \end{figure}
 
@@ -395,12 +395,12 @@ The \cleaninline{controlSDS} task illustrates communication from the web page us
        \centering
        \begin{subfigure}[t]{.5\textwidth}
                \centering
-               \fbox{\includegraphics[width=.95\textwidth]{TempHistory1}}
+               \fbox{\includegraphics[width=.95\textwidth]{TempHistory1g}}
                \caption{Web page sorted by time.}
        \end{subfigure}%
        \begin{subfigure}[t]{.5\textwidth}
                \centering
-               \fbox{\includegraphics[width=.95\textwidth]{TempHistory2}}
+               \fbox{\includegraphics[width=.95\textwidth]{TempHistory2g}}
                \caption{Web page sorted by temperature.}
        \end{subfigure}
        \caption{Web pages generated by the \cleaninline{TempHistory} \citask{} tierless web application.
@@ -489,7 +489,7 @@ there is no \gls{OS} to start the remote task, the code of the task is too big t
 The \gls{MTASK} \gls{EDSL} is designed to bridge this gap: \gls{MTASK} tasks can be communicated from the server to the sensor node, to execute within the limitations of a typical microcontroller, while providing programming abstractions that are consistent with \gls{ITASK}.
 
 Like \gls{ITASK}, \gls{MTASK} is task oriented, e.g.\ there are primitive tasks that produce intermediate values, a restricted set of task combinators to compose the tasks, and (recursive) functions to construct tasks.
-\Gls{MTASK} tasks communicate using task values or \glspl{SDS} that may be local or remote, and may be shared by some \gls{ITASK} tasks.
+Tasks in \gls{MTASK} communicate using task values or \glspl{SDS} that may be local or remote, and may be shared by some \gls{ITASK} tasks.
 
 Apart from the \gls{EDSL}, the \gls{MTASK} system contains a featherlight domain-specific \emph{operating system} running on the microcontroller.
 This \gls{OS} task scheduler receives the byte code generated from one or more \gls{MTASK} programs and interleaves the execution of those tasks. The \gls{OS} also manages \gls{SDS} updates and the passing of task results.
@@ -593,12 +593,12 @@ A similar range of commodity sensors is connected to both the Raspberry Pi and \
        \centering
        \begin{subfigure}[t]{.49\textwidth}
                \centering
-               \includegraphics[width=.9\textwidth]{wemos}
+               \includegraphics[width=.9\textwidth]{wemosg}
                \caption{A \gls{WEMOS} used in \gls{PWS} and \gls{CWS}}.%
        \end{subfigure}%
        \begin{subfigure}[t]{.49\textwidth}
                \centering
-               \includegraphics[width=.9\textwidth]{prss}
+               \includegraphics[width=.9\textwidth]{prssg}
                \caption{A Raspberry Pi used in \gls{PRS} and \gls{CRS}.}%
        \end{subfigure}
        \caption{Exposed views of sensor nodes.}%%
@@ -666,7 +666,7 @@ The main goal of the \gls{UOG} smart campus project is to provide a testbed for
 
        \item scale to no more than 10 sensors per sensor node and investigate further sensor options like measuring sound levels,
 
-       \item have access to communication channels like WiFi, Bluetooth and even wired networks.
+       \item have access to communication channels like \gls{WIFI}, Bluetooth and even wired networks.
 
        \item have a centralised database server,
 
@@ -807,7 +807,7 @@ The two tierless implementations are also similar in size: \gls{CWS} requiring 1
 
 There are several main reasons for the similarity.
 One is that the server-side code, i.e.\ for the presentation and application layers, is identical for both resource rich\slash{}constrained implementations.
-The identical server code accounts for approximately 40\% of the \gls{PWS} and \gls{PRS} codebases, and approximately 85\% of the \gls{CWS} and \gls{CRS} codebases (\cref{fig_t4t:multipercentage}).
+The identical server code accounts for approximately 40\% of the \gls{PWS} and \gls{PRS} codebases, and approximately 85\% of the \gls{CWS} and \gls{CRS} codebases (\cref{fig_t4t:multipercentage}\todo{make gray\-sca\-le}).
 For the perception and network layers on the sensor nodes, the \gls{PYTHON} and \gls{MICROPYTHON} implementations have the same structure, e.g.\ a class for each type of sensor, and use analogous libraries.
 Indeed, approaches like CircuitPython \citep{CircuitPython} allow the same code to execute on both resource-rich and resource-constrained sensor nodes.
 
@@ -874,7 +874,7 @@ The vast majority of \gls{IOT} systems are implemented using a number of differe
 
 The tierless implementations use just two conceptually-similar \glspl{DSL} embedded in the same host language, and a single paradigm (\cref{table_t4t:languages,table_t4t:paradigms}). In contrast, the tiers in \gls{PRS} and \gls{PWS} use six or more very different languages, and both imperative and declarative paradigms. Multiple languages are commonly used in other typical software systems like web stacks, e.g.\ a recent survey of open source projects reveals that on average at least five different languages are used \citep{mayer2015empirical}. Interoperating components in multiple languages and paradigms raises a plethora of issues.
 
-Interoperation \emph{increases the cognitive load on the developer} who must simultaneously think in multiple languages and paradigms. This is commonly known as semantic friction or impedance mismatch \citep{ireland2009classification}. A simple illustration of this is that the tiered \gls{PRS} source code comprises some 38 source and configuration files, whereas the tierless \gls{CRS} requires just 3 files (\cref{table_t4t:multi}). The source could be structured as a single file, but to separate concerns is structured into three modules, one each for \glspl{SDS}, types, and control logic \citep{wang_maintaining_2018}.
+Interoperation \emph{increases the cognitive load on the developer} who must simultaneously think in multiple languages and paradigms. This is commonly known as semantic friction or impedance mismatch \citep{ireland_classification_2009}. A simple illustration of this is that the tiered \gls{PRS} source code comprises some 38 source and configuration files, whereas the tierless \gls{CRS} requires just 3 files (\cref{table_t4t:multi}). The source could be structured as a single file, but to separate concerns is structured into three modules, one each for \glspl{SDS}, types, and control logic \citep{wang_maintaining_2018}.
 
 The developer must \emph{correctly interoperate the components}, e.g.\ adhere to the \gls{API} or communication protocols between components. The interoperation often entails additional programming tasks like marshalling or demarshalling data between components. For example, in the tiered \gls{PRS} and \gls{PWS} architectures, \gls{JSON} is used to serialise and deserialise data strings from the \gls{PYTHON} collector component before storing the data in the Redis database (\cref{lst_t4t:json}).
 %e.g.\ to marshall and demarshall data between components.
@@ -986,7 +986,7 @@ Strong typing identifies errors early in the development cycle, and hence plays
 % Phil: so widely known that a citation is unnecessary \citep{madsen1990strong}.
 That said, many distributed system components written in languages that primarily use static typing, like \gls{HASKELL} and Scala, use some dynamic typing, e.g.\ to ensure that the data arriving in a message has the anticipated type \citep{epstein2011towards,gupta2012akka}.
 
-In a typical tiered multi-language \gls{IOT} system the developer must integrate software in different languages with very different type systems, and potentially executing on different hardware. The challenges of maintaining type safety have long been recognised as a major component of the semantic friction in multi-language systems, e.g.\ \citep{ireland2009classification}.
+In a typical tiered multi-language \gls{IOT} system the developer must integrate software in different languages with very different type systems, and potentially executing on different hardware. The challenges of maintaining type safety have long been recognised as a major component of the semantic friction in multi-language systems, e.g.\ \citep{ireland_classification_2009}.
 
 Even if the different languages used in two components are both strongly typed, they may attribute, often quite subtly, different types to a value. Such type errors can lead to runtime errors, or the application silently reporting erroneous data. Such errors can be hard to find. Automatic detection of such errors is sometimes possible, but requires an addition tool like Jinn \citep{Jinn,Furr2005}.
 %Such errors can be hard to debug, partly because there is very limited tool support for detecting them
@@ -1111,7 +1111,7 @@ Even in low level languages some language features are disabled by default when
 
 Here we investigate the restrictions imposed by resource-constrained sensor nodes on \gls{MTASK}, in comparison with \gls{ITASK}. While \gls{ITASK} and \gls{MTASK} are by design superficially similar languages, to execute on resource-constrained sensor nodes \gls{MTASK} tasks are more restricted, and have a different semantics.
 
-\Gls{MTASK} programs do not support user defined higher order functions, the only higher order functions available are the predefined \gls{MTASK} combinators.
+Programs in \gls{MTASK} do not support user defined higher order functions, the only higher order functions available are the predefined \gls{MTASK} combinators.
 Programmers can, however, use any construct of the \gls{CLEAN} host language to construct an \gls{MTASK} program, including higher order functions and arbitrary data types. For example folding an \gls{MTASK} combinator over a list of tasks.
 The only restriction is that any higher order function must be macro expanded to a first order \gls{MTASK} program before being compiled to byte code.
 As an example in \cref{lst_t4t:mtasktemp} we use \cleaninline{temperature dht >>~.} \cleaninline{setSds localSds} instead of \cleaninline{temperature dht >>~.} \cleaninline{\\temp -> setSds localSds temp}.
@@ -1121,9 +1121,9 @@ In contrast to \gls{ITASK}, \gls{MTASK} programs have no user defined or recursi
 Due to the language being shallowly embedded, pattern matching and field selection on user defined types is not readily available and thus needs to be built into the language by hand.
 Alleviating this limitation remains future work.
 
-\Gls{MTASK} programs mainly use strict rather than lazy evaluation to minimise the requirement for a variable size heap. This has no significant impact for the \gls{MTASK} programs we have developed here, nor in other \gls{IOT} applications we have engineered.
+Programs in \gls{MTASK} mainly use strict rather than lazy evaluation to minimise the requirement for a variable size heap. This has no significant impact for the \gls{MTASK} programs we have developed here, nor in other \gls{IOT} applications we have engineered.
 
-\Gls{MTASK} abstractions are less easily extended than \gls{ITASK}. For example \gls{ITASK} can be extended with a new combinator that composes a specific set of tasks for some application.
+Abstractions in \gls{MTASK} are less easily extended than \gls{ITASK}. For example \gls{ITASK} can be extended with a new combinator that composes a specific set of tasks for some application.
 Without higher order functions the equivalent combinator can often not be expressed in \gls{MTASK}, and adding it to \gls{MTASK} requires extending the \gls{DSL} rather than writing a new definition in it.
 On the other hand, it is possible to outsource this logic to the \gls{ITASK} program as \gls{MTASK} and \gls{ITASK} tasks are so tightly integrated.
 
@@ -1150,7 +1150,7 @@ The downside of this direct control is that \gls{CWS} has to handle some excepti
 \Cref{table_t4t:languagecomparison} summarises the differences between the \gls{CLEAN} \gls{IOT} \gls{EDSL} and their host language.
 The restrictions imposed by a resource-constrained execution environment on the tierless \gls{IOT} language are relatively minor. Moreover the \gls{MTASK} programming abstraction is broadly compatible with \gls{ITASK}. As a simple example compare the \gls{ITASK} and \gls{MTASK} temperature sensors in \cref{lst_t4t:itaskTempFull,lst_t4t:mtasktemp}. As a more realistic example, the \gls{MTASK} based \gls{CWS} smart campus implementation is similar to the \gls{ITASK} based \gls{CRS}, and requires less than 10\% additional code: 166 \gls{SLOC} compared with 155 \gls{SLOC} (\cref{table_t4t:multi}).
 
-Even with these restrictions, \gls{MTASK} programming is at a far higher level of abstraction than almost all bare metal languages, e.g.\ BIT, PICBIT, PICOBIT and Microscheme. That is \gls{MTASK} provides a set of higher order task combinators, shared distributed data stores, \etc. (\cref{sec_t4t:mtasks}). Moreover, it seems that common sensor node programs are readily expressed using \gls{MTASK}. In addition to the \gls{CWTS} and \gls{CWS} systems outlined here, other case studies include Arduino examples as well as some bigger tasks \citep{koopman_task-based_2018,lubbers_writing_2019,LubbersMIPRO}. We conclude that the programming of sensor tasks is well-supported by both \glspl{DSL}.
+Even with these restrictions, \gls{MTASK} programming is at a far higher level of abstraction than almost all bare metal languages, e.g.\ BIT, PICBIT, PICOBIT and Microscheme. That is \gls{MTASK} provides a set of higher order task combinators, shared distributed data stores, \etc. (\cref{sec_t4t:mtasks}). Moreover, it seems that common sensor node programs are readily expressed using \gls{MTASK}. In addition to the \gls{CWTS} and \gls{CWS} systems outlined here, other case studies include Arduino examples as well as some bigger tasks \citep{koopman_task-based_2018,lubbers_writing_2023,lubbers_multitasking_2019}. We conclude that the programming of sensor tasks is well-supported by both \glspl{DSL}.
 
 \section{Conclusion}%
 \label{sec_t4t:Conclusion}