errata
[phd-thesis.git] / tvt / tvt.tex
index 2b5ac47..7a8d120 100644 (file)
@@ -6,12 +6,13 @@
 
 \begin{document}
 \input{subfileprefix}
-\chapter{Could tierless languages reduce IoT development grief?}%
+\chapter{Tiered versus tierless programming}%
 \label{chp:smart_campus}
 
 \begin{chapterabstract}
-       \Gls{IOT} software is notoriously complex, conventionally comprising multiple tiers.
-       Traditionally an \gls{IOT} developer must use multiple programming languages and ensure that the components interoperate correctly. A novel alternative is to use a single \emph{tierless} language with a compiler that generates the code for each component and ensures their correct interoperation.
+       \Gls{IOT} software is notoriously complex, usually comprising multiple tiers.
+       Traditionally an \gls{IOT} developer must use multiple programming languages and ensure that the components interoperate correctly.
+       A novel alternative is to use a single \emph{tierless} language with a compiler that generates the code for each component and their correct interoperation.
 
        We report a systematic comparative evaluation of two tierless language technologies for \gls{IOT} stacks: one for resource-rich sensor nodes (\gls{CLEAN} with \gls{ITASK}), and one for resource-constrained sensor nodes (\gls{CLEAN} with \gls{ITASK} and \gls{MTASK}).
        The evaluation is based on four implementations of a typical smart campus application: two tierless and two \gls{PYTHON}-based tiered.
@@ -36,9 +37,9 @@ Conventional \gls{IOT} software architectures require the development of separat
        \item The developer must deal with the potentially diverse failure modes of each component, and of component interoperation.
 \end{enumerate*}
 
-A radical alternative development paradigm uses a single \emph{tierless} language that synthesizes all components\slash{}tiers in the software stack. There are established \emph{tierless} languages for web stacks, e.g.\ Links \citep{cooper2006links} or Hop \citep{serrano2006hop}.
+A radical alternative development paradigm uses a single \emph{tierless} language that synthesises all components\slash{}tiers in the software stack. There are established \emph{tierless} languages for web stacks, e.g.\ Links \citep{cooper2006links} or Hop \citep{serrano2006hop}.
 In a tierless language the developer writes the application as a single program. The code for different tiers is simultaneously checked by the compiler, and compiled to the required component languages. For example, Links compiles to HTML and JavaScript for the web client and to SQL on the server to interact with the database system. Tierless languages for \gls{IOT} stacks are more recent and less common, examples include
-Potato \citep{troyer_building_2018} and \gls{CLEAN} with \imtask{} \citep{lubbers_interpreting_2019}.
+Potato \citep{troyer_building_2018}, and \gls{CLEAN} with \imtask{} \citep{lubbers_interpreting_2019}.
 
 \Gls{IOT} sensor nodes may be microcontrollers with very limited compute resources, or supersensors: resource-rich single board computers like a Raspberry Pi. A tierless language may target either class of sensor node, and microcontrollers are the more demanding target due to the limited resources, e.g.\ small memory, executing on bare metal, \etc.
 
@@ -81,7 +82,7 @@ As a prototyping exercise, we use modest commodity
 sensor nodes (i.e.\ Raspberry Pis) and low-cost, low-precision sensors
 for indoor environmental monitoring.
 
-We have deployed sensor nodes into 12 rooms in two buildings. The \gls{IOT} system has an online data store, providing live
+Sensor nodes have been deployed into 12 rooms in two buildings. The \gls{IOT} system has an online data store, providing live
 access to sensor data through a RESTful \gls{API}.
 This allows campus stakeholders to add functionality at a business layer above the layers that we consider here. To date,
 simple apps have been developed including room temperature
@@ -203,7 +204,6 @@ Only a small fraction of these systems are described in the academic literature,
 
 This study compares a pair of tierless \gls{IOT} languages with conventional tiered \gls{PYTHON} \gls{IOT} software. \Citask{} and \cimtask{} represent a specific set of tierless language design decisions, however many alternative designs are available. Crucially the limitations of the tierless \gls{CLEAN} languages, e.g.\ that they currently provide limited security, should not be seen as limitations of tierless technologies in general. This section briefly outlines key design decisions for tierless \gls{IOT} languages, discusses alternative designs, and describes the \gls{CLEAN} designs. The \gls{CLEAN} designs are illustrated in the examples in the following section.
 
-
 \subsubsection{Tier splitting and placement}
 A key challenge for a tierless language is to determine which parts of the program correspond to a particular tier and hence should be executed by a specific component on a specific host.
 
@@ -244,7 +244,8 @@ Tierless languages may adopt a range of communication paradigms for communicatin
 
 Security is a major issue and a considerable challenge for many \gls{IOT} systems \citep{alhirabi_security_2021}. There are potentially security issues at each layer in an \gls{IOT} application (\cref{fig_t4t:iot_arch}). The security issues and defence mechanisms at the application and presentation layers are relatively standard, e.g.\ defending against SQL injection attacks. The security issues at the network and perception layers are more challenging. Resource-rich sensor nodes can adopt some standard security measures like encrypting messages, and regularly applying software patches to the operating system. However, microcontrollers often lack the computational resources for encryption, and it is hard to patch their system software because the program is often stored in flash memory. In consequence there are infamous examples of \gls{IOT} systems being hijacked to create botnets \citep{203628,herwig_measurement_2019}.
 
-Securing the entire stack in a conventional tiered \gls{IOT} application is particularly challenging as the stack is implemented in a collection of programming languages with low level programming and communication abstractions. In such polyglot distributed systems it is hard to determine, and hence secure, the flow of data between components. In consequence a small mistake may have severe security implications. 
+Securing the entire stack in a conventional tiered \gls{IOT} application is particularly challenging as the stack is implemented in a collection of programming languages with low level programming and communication abstractions. In such polyglot distributed systems it is hard to determine, and hence secure, the flow of data between components.
+As a consequence, a small mistake may have severe security implications. 
 
 A number of characteristics of tierless languages help to improve security. Communication and placement vulnerabilities are minimised as communication and placement are automatically generated and checked by the compiler. So injection attacks and the exploitation of communication\slash{}placement protocol bugs are less likely. Vulnerabilities introduced by mismatched types are avoided as the entire system is type checked. Moreover, tierless languages can exploit language level security techniques. For example languages like Jif\slash{}split \citep{zdancewic2002secure} and Swift \citep{chong2007secure} place components to protect the security of data. Another example are programming language technologies for controlling information flow, and these can be used to improve security. For example Haski uses them to improve the security of \gls{IOT} systems \citep{valliappan_towards_2020}. 
 
@@ -520,6 +521,7 @@ While this simple application makes limited use of the \gls{MTASK} \gls{EDSL}, i
 Function composition (\cref{lst_t4t:mtasktemp:o}) and currying (\cref{lst_t4t:mtasktemp:setSds}) are inherited from the \gls{CLEAN} host language.
 As \gls{MTASK} tasks are dynamically compiled, it is also possible to select and customise tasks as required at runtime.
 For example, the interval used in the \cleaninline{rpeatevery} task (\cref{lst_t4t:mtasktemp:rpeatevery}) could be a parameter to the \cleaninline{devTask} function.
+\newpage%
 
 \begin{lstClean}[%
        numbers=left,
@@ -555,7 +557,7 @@ devTask =
 
 mainTask :: Task Real
 mainTask
-       =   withDevice deviceInfo \dev -> liftmTask} devTask dev[+\label{lst_t4t:mtasktemp:liftmtask}+][+\label{lst_t4t:mtasktemp:withdevice}+][+\label{lst_t4t:mtasktemp:co2}\srcmark{CO}+]
+       =   withDevice deviceInfo \dev -> liftmTask devTask dev[+\label{lst_t4t:mtasktemp:liftmtask}+][+\label{lst_t4t:mtasktemp:withdevice}+][+\label{lst_t4t:mtasktemp:co2}\srcmark{CO}+]
        -|| viewSharedInformation [] latestTemp[+\label{lst_t4t:mtasktemp:wi1}\srcmark{WI}+]
        <<@ Title "Latest temperature"[+\label{lst_t4t:mtasktemp:wi2}\srcmark{WI}+]
 \end{lstClean}
@@ -687,11 +689,10 @@ Observation of the four implementations shows that they operate as expected, e.g
 All four implementations use an identical set of inexpensive sensors, so we expect the accuracy of the data collected is within tolerance levels. This is validated by comparing \gls{PRS} and \gls{PWS} sensor nodes deployed in the same room for some minutes. The measurements show only small variances, e.g.\ temperatures recorded differ by less than \qty{0.4}{\celcius}, and light by less than \qty{1}{lux}. For this room monitoring application precise timings are not critical, and we don't compare the timing behaviours of the implementations.
 
 \subsubsection{Memory and power consumption}%
-%\subsubsection{Memory Consumption}%
 \label{sec_t4t:MemPower}
 
 \paragraph{Memory} By design sensor nodes are devices with limited computational capacity, and memory is a key restriction. Even supersensors often have less than a \unit{\gibi\byte} of memory, and microcontrollers often have just tens of \unit{\kibi\byte}.
-As the tierless languages synthesize the code to be executed on the sensor nodes, we need to confirm that the generated code is sufficiently memory efficient.
+As the tierless languages synthesise the code to be executed on the sensor nodes, we need to confirm that the generated code is sufficiently memory efficient.
 
 \begin{table}
        \centering
@@ -731,7 +732,7 @@ This section investigates whether tierless languages make \gls{IOT} programming
 \paragraph{Code size}
 is widely recognised as an approximate measure of the development and maintenance effort required for a software system \citep{rosenberg1997some}. \Gls{SLOC} is a common code size metric, and is especially useful for multi-paradigm systems like \gls{IOT} systems. It is based on the simple principle that the more \gls{SLOC}, the more developer effort and the increased likelihood of bugs \citep{rosenberg1997some}. It is a simple measure, not dependent on some formula, and can be automatically computed \citep{sheetz2009understanding}.
 
-Of course \gls{SLOC} must be used carefully as it is easily influenced by programming style, language paradigm, and counting method \citep{alpernaswonderful}. Here we are counting code to compare development effort, use the same idiomatic programming style in each component, and only count lines of code, omitting comments and blank lines.
+Of course \gls{SLOC} must be used carefully as it is easily influenced by programming style, language paradigm, and counting method \citep{alpernaswonderful}. Here we are counting lines of code to compare development effort, use the same idiomatic programming style in each component, and only count lines of code, omitting comments and blank lines.
 
 \Cref{table_t4t:multi} enumerates the \gls{SLOC} required to implement the \gls{UOG} smart campus functionalities in \gls{PWS}, \gls{PRS}, \gls{CWS} and \gls{CRS}. Both \gls{PYTHON} and \gls{CLEAN} implementations use the same server and communication code for Raspberry Pi and for \gls{WEMOS} sensor nodes (rows 5--7 of the table).
 The Sensor Interface (SI) refers to code facilitating the communication between the peripherals and the sensor node software. % formerly hardware interface
@@ -844,14 +845,14 @@ A caveat is that the smart campus system is relatively simple, and developing mo
                \midrule
                Code Location & Functionality & \gls{PYTHON} & \gls{CLEAN}\\
                \midrule
-               Sensor Node   & Sensor Int.   & imperative   & declarative\\
-                             & Sensor Node   & imperative   & declarative\\
+               Sensor Node   & Sensor Interface   & Imperative   & Declarative\\
+                             & Sensor Node   & Imperative   & Declarative\\
                \midrule
-               Server        & Manage Nodes  & imperative   & declarative\\
-                             & Web Int.      & both         & declarative\\
-                             & Database Int. & both         & declarative\\
+               Server        & Manage Nodes  & Imperative   & Declarative\\
+                             & Web Interface      & Both         & Declarative\\
+                             & Database Interface & Both         & Declarative\\
                \midrule
-               Communication & Communication & imperative   & declarative\\
+               Communication & Communication & Imperative   & Declarative\\
                \midrule
                              & Total         & 2            & 1 \\
                \bottomrule
@@ -867,7 +868,6 @@ Interoperation \emph{increases the cognitive load on the developer} who must sim
 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 unmarshalling 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}).
 
 \begin{lstPython}[caption={\Gls{JSON} Data marshalling in \gls{PRS} and \gls{PWS}: sensor node above, server below.},label={lst_t4t:json}]
-
 channel = 'sensor_status.%s.%s' % (hostname,
        sensor_types.sensor_type_name(s.sensor_type))
                self.r.publish(channel, s.SerializeToString())
@@ -920,7 +920,7 @@ The exchange of data, user interface, and communication are all automatically ge
 
 Another reason that the tierless \gls{CLEAN} implementations are concise is because they use powerful higher order \gls{IOT} programming abstractions.
 For comprehensibility the simple temperature sensor from \cref{sec_t4t:mtasks} (\cref{lst_t4t:mtasktemp}) is used to compare the expressive power of \gls{CLEAN} and \gls{PYTHON}-based \gls{IOT} programming abstractions.
-There are implementations for all four configurations: \gls{PRTS} (\gls{PYTHON} Raspberry Pi Temperature Sensor)\footnotemark, \gls{PWTS}\footnotemark[\value{footnote}],
+There are implementations for all four configurations: \gls{PRTS}\footnotemark, \gls{PWTS}\footnotemark[\value{footnote}],
 \footnotetext{Lubbers, M.; Koopman, P.; Ramsingh, A.; Singer, J.; Trinder, P. (2021): Source code, line counts and memory stats for PRS, PWS, PRT and PWT.\ Zenodo.\ \href{https://doi.org/10.5281/zenodo.5081386}{10.5281/zenodo.5081386}.} \gls{CRTS}\footnotemark{} and \gls{CWTS}\footnotemark[\value{footnote}].
 \footnotetext{Lubbers, M.; Koopman, P.; Ramsingh, A.; Singer, J.; Trinder, P. (2021): Source code, line counts and memory stats for CRS, CWS, CRTS and CWTS.\ Zenodo.\ \href{https://doi.org/10.5281/zenodo.5040754}{10.5281/zenodo.5040754}.}
 but as the programming abstractions are broadly similar, we compare only the \gls{PWTS} and \gls{CWTS} implementations.
@@ -1009,7 +1009,7 @@ failover :: [TCPSettings] (Main (MTask BCInterpret a)) -> Task a
 failover []     _     = throw "Exhausted device pool"
 failover [d:ds] mtask = try (withDevice d (liftmTask mtask)) except
 where except MTEUnexpectedDisconnect = failover ds mtask
-         except _                       = throw e
+         except e                       = throw e
 \end{lstClean}
 
 In the \gls{UOG} smart campus application, this can be done by creating a pool of sensor nodes for each room and when a sensor node fails, assign another one to the task.
@@ -1042,6 +1042,7 @@ In summary, while a tiered approach makes replacing components easy, refactoring
 \label{sec_t4t:support}
 Community and tool support are essential for engineering reliable production software. \Gls{PRS} and \gls{PWS} are both \gls{PYTHON} based, and \gls{PYTHON}\slash\gls{MICROPYTHON} are among the most popular programming languages \citep{cass2020top}. \Gls{PYTHON} is also a common choice for some tiers of \gls{IOT} applications \citep{tanganelli2015coapthon}.
 Hence, there are a wide range of development tools like \glspl{IDE} and debuggers, a thriving community and a wealth of training material. There are even specialised \gls{IOT} Boards like PyBoard \& WiPy that are specifically programmed using \gls{PYTHON} variations like \gls{MICROPYTHON}.
+\pagebreak
 
 In contrast, tierless languages are far less mature than the languages used in tiered stacks, and far less widely adopted.
 This means that for \gls{CWS} and \gls{CRS} there are fewer tools, a far smaller developer community, and less training material available.
@@ -1064,7 +1065,7 @@ This section compares the \gls{ITASK} and \gls{MTASK} \glspl{EDSL}, with referen
 
 \begin{table}
        \small
-       \caption{Comparing tierless \gls{IOT} languages for resource-rich sensor nodes (\gls{ITASK} \gls{EDSL}), for resource-constrained sensor nodes (\gls{MTASK} \gls{EDSL}), and their \gls{CLEAN} host language.}%
+       \caption{Comparing tierless \gls{IOT} \glspl{DSL} for resource-rich sensor nodes (\gls{ITASK}), for resource-constrained sensor nodes (\gls{MTASK}), and their \gls{CLEAN} host language.}%
        \label{table_t4t:languagecomparison}
        \begin{tabular}{llll}
                \toprule
@@ -1079,10 +1080,10 @@ This section compares the \gls{ITASK} and \gls{MTASK} \glspl{EDSL}, with referen
                User-defined datatypes      & Yes    & Yes         & No \\
                Task oriented               & No     & Yes         & Yes \\
                Higher-order tasks          & {--}   & Yes         & No \\
-               Execution Target & Commodity PC & Commodity PC & microcontroller\\
-                                &              & and Browser & microcontroller\\
+               Execution Target & Commodity PC & Commodity PC & Microcontroller\\
+                                &              & and browser & Microcontroller\\
                Language Implementation & Compiled or & Compiled and & Interpreted\\
-                                       & interpreted & interpreted & Interpreted\\
+                                       & interpreted & interpreted & \\
                \bottomrule
        \end{tabular}
 \end{table}