up
[phd-thesis.git] / intro / intro.tex
index 5e1453c..0997df7 100644 (file)
        \end{itemize}
 \end{chapterabstract}
 
-There are at least 13.4 billion devices connected to the internet at the time of writing\footnote{\refurl{https://transformainsights.com/research/tam/market}{\formatdate{13}{10}{2022}}}.
-Each of these senses, acts, or otherwise interacts with people, other computers, and the environment surrounding us.
+There are at least 13.4 billion devices connected to the internet at the time of writing \citep{transformation_insights_current_2023}.%\footnote{\refurl{https://transformainsights.com/research/forecast/highlights}{\formatdate{19}{01}{2023}}}.
+Each of these sense, act, or otherwise interact with people, other computers, and the environment surrounding us.
 Despite their immense diversity, they are all computers.
 And as computers, they require software to operate.
 
 An increasing amount of these connected devices are so-called \emph{edge devices} that operate in the \gls{IOT}.
-Edge devices are the leafs of the \gls{IOT} systems, they perform the interaction with the physical world and are physically embedded in the fabric.
+Edge devices are the leafs of the \gls{IOT} systems, they perform the interaction with the physical world and are often physically embedded in the fabric.
 They usually reside in hard-to-reach places such as light bulbs, smart electricity meters, or even farm animals.
-Equipped with a lot of connectivity for integrating peripherals such as sensors and actuators, makes them very suitable to interact with their surroundings.
+Microcontrollers are equipped with a lot of connectivity for integrating peripherals such as sensors and actuators.
+The connectivity makes them very suitable to interact with their surroundings.
 Typically, these edge devices are powered by microcontrollers.
 These miniature computers contain integrated circuits that accommodate a microprocessor designed for use in embedded applications.
-Hence, microcontrollers are therefore cheap; tiny; have little memory; and contain a slow, but energy-efficient processor.
+Hence, microcontrollers are cheap; tiny; have little memory; and contain a slow, but energy-efficient processor.
 
-Unlike the conductor in the orchestra waving their baton to instruct the ensemble of instruments, in the universe of software there is room for little error.
-Moreover, in dynamic \gls{IOT} applications, often there is not even a conductor or coordinator.
+Unlike the conductor in an orchestra waving their baton to instruct the ensemble of instruments, in the universe of software there is room for little error.
+Moreover, in dynamic \gls{IOT} applications, often there is not even a coordinating conductor.
 Even though edge devices—the instruments—come and go, perform their own pieces, or are instructed to perform a certain piece, they operate without a central authority.
 In the traditional setting, an \gls{IOT} engineer has to program each device and their interoperation using different programming paradigms, programming languages, and abstraction levels.
-Thus resulting in semantic friction, making programming and maintaining \gls{IOT} systems is a complex and error-prone process.
+Thus resulting in semantic friction, which makes programming and maintaining \gls{IOT} systems a complex and error-prone process.
 
 This dissertation describes the research carried out around orchestrating these complex \gls{IOT} systems using \gls{TOP}.
 \Gls{TOP} is an innovative tierless programming paradigm for interactive multi-layered systems.
-By utilising advanced compiler technologies, much of the internals, communications, and interoperation between the tiers\slash{}layers of the applications is automatically generated.
+By utilising advanced compiler technologies, much of the internals, communication, and interoperation between the tiers or layers of the applications is automatically generated.
 From a single declarative specification of the work required, the compiler makes a ready-for-work application consisting of interconnected components for all tiers.
-For example, the \gls{TOP} system \gls{ITASK} can be used to program all layers of a multi-user distributed web applications from a single source specification.
-It is implemented in \gls{CLEAN}, executes also in \gls{CLEAN}'s general-purpose run time, and requires relatively powerful hardware.
+For example, the \gls{TOP} system \gls{ITASK} is used to program all layers of multi-user distributed web applications from a single source specification.
+It is implemented in \gls{CLEAN}, executes in \gls{CLEAN}'s general-purpose run time, and therefore requires relatively powerful hardware.
 The high hardware requirements are no problem for regular computers but impractical for the average edge device.
 
 This is where \glspl{DSL} must be brought into play.
@@ -51,8 +52,8 @@ Consequently, jargon does not have to be expressed in the language itself, but t
 Furthermore, the \gls{DSL} can eschew language or system features that are irrelevant for the domain.
 
 To incorporate the plethora of edge devices in the orchestra of a \gls{TOP} system, the \gls{MTASK} system is used.
-\Gls{MTASK} is a novel programming language for programming \gls{IOT} edge devices using \gls{TOP}.
-Where \gls{ITASK} abstracts away from the gritty details of multi-tier web applications, \gls{MTASK} has domain-specific abstractions for \gls{IOT} edge devices, maintaining the high abstraction level that \gls{TOP} generally offers.
+The \gls{MTASK} language is a novel programming language for programming \gls{IOT} edge devices using \gls{TOP}.
+Where \gls{ITASK} abstracts away from the gritty details of multi-tier web applications, \gls{MTASK} has domain-specific abstractions for \gls{IOT} edge devices, maintaining the high abstraction level that \gls{TOP} offers.
 As it is integrated with \gls{ITASK}, it allows for all layers of an \gls{IOT} application to be programmed from a single source.
 
 \section{Reading guide}%
@@ -66,8 +67,8 @@ This dissertation consists of three episodes.
 \Cref{prt:dsl} is a paper-based---otherwise known as cumulative---episode containing chapters that provide insight in advanced \gls{DSL} embedding techniques for \gls{FP} languages.
 The chapters are readable independently.
 \Cref{prt:top} is a monograph showing \gls{MTASK}, a \gls{TOP} \gls{DSL} for the \gls{IOT}.
-Hence, the chapters are best read in order.
-It introduces \gls{IOT} edge device programming, shows the complete \gls{MTASK} language, provides details on how \gls{MTASK} is integrated with \gls{ITASK}, shows how the byte code compiler is implemented, with a guide for green computing with \gls{ITASK} and ends with a conclusion and overview of future and related work.
+Hence, the chapters in this episode are best read in order.
+It introduces \gls{IOT} edge device programming, shows the complete \gls{MTASK} language, provides details on how \gls{MTASK} is integrated with \gls{ITASK}, shows how the byte code compiler is implemented, presents a guide for green computing with \gls{ITASK}, and ends with a conclusion and overview of future and related work.
 \Cref{prt:tvt} is a single chapter based on a journal article in which traditional tiered \gls{IOT} programming is qualitatively and quantitatively compared to tierless programming using a real-world application.
 The chapter is readable independently.
 
@@ -97,38 +98,38 @@ For the intents and purposes of this thesis, the layered architecture as shown i
        \label{fig:iot-layers}
 \end{figure}
 
-To explain the tiers, an example \gls{IOT} application---home automation---is dissected accordingly.
-Closest to the end-user is the presentation layer, it provides the interface between the user and \gls{IOT} systems.
-In home automation this may be a web interface, or an app used on a phone or wall-mounted tablet to interact with edge devices and view sensor data.
+To explain the tiers, an example \gls{IOT} application---home automation---is dissected.
+Closest to the end-user is the presentation layer, it provides the interface between the user and the \gls{IOT} systems.
+In home automation this may be a web interface, an app used on a phone, or wall-mounted tablet to interact with edge devices and view sensor data.
 
-The application layer provides the \glspl{API}, data interfaces, data processing, and data storage of \gls{IOT} systems.
+The application layer provides the \glspl{API}, data interfaces, data storage processing, and data processing of \gls{IOT} systems.
 A cloud server or local server provides this layer in a typical home automation application.
 
 The perception layer---also called edge layer---collects the data and interacts with the environment.
 It consists of edge devices such as microcontrollers equipped with various sensors and actuators.
-In home automation this layer consists of all the devices hosting sensors and actuators such as smart light bulbs, actuators to open doors, or temperature and humidity sensors.
+In home automation this layer consists of all devices hosting sensors and actuators such as smart light bulbs, actuators to open doors, or temperature and humidity sensors.
 
 All layers are connected using the network layer.
 In some applications this is implemented using conventional networking techniques such as Wi-Fi or Ethernet.
-However, network technology that is tailored to the needs of the specific interconnection between the two layers have become increasingly popular.
+However, network technology that is tailored to the needs of the specific interconnection between the two layers are increasingly popular.
 Examples of this are BLE, LoRa, ZigBee, and LTE-M as a communication protocol for connecting the perception layer to the application layer using \gls{IOT} transport protocols such as \gls{MQTT}.
-Protocols such as HTTP, AJAX, and WebSocket connecting the presentation layer to the application layer that are designed for the use in web applications. 
+Protocols such as HTTP, AJAX, and WebSocket connecting the presentation layer to the application layer that are designed for the use in web applications.
 
 Across the layers, the devices are a large heterogeneous collection of different platforms, protocols, paradigms, and programming languages often resulting in impedance problems or semantic friction between layers when programming \citep{ireland_classification_2009}.
 Even more so, the perception layer itself is often a heterogeneous collection of microcontrollers in itself, each having their own peculiarities, language of choice, and hardware interfaces.
-As edge hardware needs to be cheap, small-scale, and energy efficient, the microcontrollers used to power them do not have a lot of computational power, only a soup\c{c}on of memory, and little communication bandwidth.
+As edge hardware needs to be cheap, small scale, and energy efficient, the microcontrollers used to power them do not have a lot of computational power, only a soup\c{c}on of memory, and little communication bandwidth.
 Typically, these devices are unable to run a full-fledged general-purpose \gls{OS}.
 Rather they employ compiled firmware written in imperative languages that combines all tasks on the device in a single program.
 While devices are getting a bit faster, smaller, and cheaper, they keep these properties to an extent.
-For example, more powerful microcontrollers are capable of running \gls{RTOS}, but this still requires many resources and fixes the programs at compile time.
-As a consequence, the flexibility is greatly reduced for dynamic systems in which tasks are created on the fly, executed on demand, or require parallel execution.
+For example, more powerful microcontrollers are capable of running \glspl{RTOS}, but this still requires a lot of resources and fixes the programs at compile time.
+As a consequence, the flexibility is greatly reduced for dynamic systems in which tasks are created on the fly, executed on demand, require parallel execution, or have dynamic scheduling behaviour.
 As program memory is mostly flash-based and only lasts a couple of thousands of writes before it wears out, it is not suitable for repeated reconfiguring and reprogramming.
 
 These problems can be mitigated by dynamically sending code to be interpreted to the microcontroller.
 With interpretation, a specialized interpreter is flashed in the program memory once it receives the program code to execute at run time.
 Therefore, as the programs are not stored in the flash memory, it does not wear out.
 It is challenging to create interpreters for small edge devices due to the severe hardware restrictions.
-This dissertation describes a \gls{DSL} that encompasses the high-level programming concepts of \gls{TOP}, while it can be executed on edge devices with very limited requirements.
+This dissertation describes a \gls{DSL} that includes the high-level programming concepts of \gls{TOP}, while it can be executed on edge devices with very limited hardware requirements.
 It does so by compiling the \gls{DSL} to byte code that is executed in a feather-light domain-specific \gls{OS}.
 
 \section{\texorpdfstring{\Glsxtrlongpl{DSL}}{Domain-specific languages}}%
@@ -136,11 +137,11 @@ It does so by compiling the \gls{DSL} to byte code that is executed in a feather
 % General
 Programming languages can be divided up into two categories: \glspl{DSL} and \glspl{GPL} \citep{fowler_domain_2010}.
 Where \glspl{GPL} are not made with a demarcated area in mind, \glspl{DSL} are tailor-made for a specific domain.
-Writing idiomatic domain-specific code in a \gls{DSL} is easier and requires less background knowledge about a \gls{GPL}.
+Writing idiomatic domain-specific code in a \gls{DSL} is easier and requires less background knowledge.
 This does come at the cost of the \gls{DSL} being sometimes less expressive to an extent that it may not even be Turing complete.
 \Glspl{DSL} come in two main flavours: standalone and embedded (\cref{sec:standalone_embedded})\footnote{Standalone and embedded are also called external and internal respectively.}.
 Standalone languages are languages for which the complete toolchain has been developed, just as for any other \gls{GPL}.
-Embedded languages piggyback on an existing \gls{GPL}, they are defined in terms of their host language.
+Embedded languages piggyback on an existing language, they are defined in terms of their host language.
 \Glspl{EDSL} can further be classified into heterogeneous and homogeneous languages (\cref{sec:hetero_homo}).
 In homogeneous languages all components are integrated whereas in heterogeneous \glspl{DSL}, some parts are agnostic of the other systems, e.g.\ a \gls{DSL} that generates code for execution on a totally different system.
 This hyponymy is shown in \cref{fig:hyponymy_of_dsls}.
@@ -148,7 +149,7 @@ This hyponymy is shown in \cref{fig:hyponymy_of_dsls}.
 \begin{figure}
        \centering
        \includestandalone{hyponymy_of_dsls}
-       \caption{A hyponymy of \glspl{DSL} (adapted from \citet[\citepage{2}]{mernik_extensible_2013})}%
+       \caption{A hyponymy of \glspl{DSL} (adapted from \citet[\citepage{2}]{mernik_extensible_2013}).}%
        \label{fig:hyponymy_of_dsls}
 \end{figure}
 
@@ -157,16 +158,16 @@ This hyponymy is shown in \cref{fig:hyponymy_of_dsls}.
 \glspl{DSL} where historically created as standalone languages, meaning that all machinery is developed solely for the language.
 The advantage of this approach is that the language designer is free to define the syntax and type system of the language as they wish, not being restricted by any constraint.
 Unfortunately it also means that they need to develop a compiler or interpreter, and all the scaffolding for the language, making standalone \glspl{DSL} costly to create.
-Examples of standalone \glspl{DSL} are \TeX, \LaTeX, make, yacc, XML, SQL, \etc.
+Examples of standalone \glspl{DSL} are \TeX, make, yacc, XML, SQL, \etc.
 
-The dichotomous approach is embedding the \gls{DSL} in a host language, i.e.\ \glspl{EDSL} \citep{hudak_modular_1998}.
+The dichotomous approach to standalone \glspl{DSL} is embedding the \gls{DSL} in a host language, i.e.\ \glspl{EDSL} \citep{hudak_modular_1998}.
 By defining the language as constructs in the host language, much of the machinery is inherited \citep{krishnamurthi_linguistic_2001}.
-This greatly reduces the cost of creating embedded languages and shields the user from having to learn a general-purpose language and toolchain.
+This greatly reduces the cost of creating embedded languages and shields the user from having to learn the host language and toolchain.
 However, there are two sides to this coin.
-If the syntax of the host language is not very flexible, the syntax of the \gls{DSL} may become clumsy.
+If the syntax of the host language is not very flexible, the syntax of the \gls{DSL} could become clumsy.
 Furthermore, \gls{DSL} errors shown to the programmer may be larded with host language errors, making it difficult for a non-expert of the host language to work with the \gls{DSL}.
 \Gls{FP} languages are especially suitable for hosting embedded \glspl{DSL}.
-They offer tooling for building abstraction levels by a strong and versatile type systems, minimal but flexible syntax, and offer referential transparency.
+They offer tooling for building abstraction levels by a strong and versatile type systems, minimal but flexible syntax, and referential transparency.
 
 \subsection{Heterogeneity and homogeneity}%
 \label{sec:hetero_homo}
@@ -177,18 +178,18 @@ They offer tooling for building abstraction levels by a strong and versatile typ
 }
 \end{quote}
 
-Homogeneous \glspl{EDSL} are therefore languages that are solely defined as an extension to their host language.
+Homogeneous \glspl{EDSL} are languages that are solely defined as an extension to their host language.
 They often restrict features of the host language to provide a safer interface or capture an idiomatic pattern in the host language for reuse.
 The difference between a library and a homogeneous \glspl{EDSL} is not always clear.
 Examples of homogeneous \glspl{EDSL} are libraries such as ones for sets, regions, but also more complex tasks such as \glspl{GUI}.
 
 On the other hand, heterogeneous \glspl{EDSL} are languages that are not executed in the host language.
 For example, \citet{elliott_compiling_2003} describe the language Pan, for which the final representation in the host language is a compiler that will, when executed, generate code for a completely different target platform.
-In fact, \gls{ITASK} and \gls{MTASK} are embedded \glspl{DSL}.
-Programs written in \gls{ITASK} run in the host language, and is a homogeneous \gls{DSL}.
+In fact, both \gls{ITASK} and \gls{MTASK} are \glspl{EDSL}.
+Programs written in \gls{ITASK} run in the host language, and it is a homogeneous \gls{DSL}.
 Tasks written using \gls{MTASK} are dynamically compiled to byte code for an edge device, making it a heterogeneous \gls{DSL}.
 The interpreter running on the edge device has no knowledge of the higher level task specification.
-It just interprets the byte code it was sent, rewrites the tasks and publishes task values and \gls{SDS} updates.
+It just interprets the byte code it was sent and takes care of the communication.
 
 \section{\texorpdfstring{\Glsxtrlong{TOP}}{Task-oriented programming}}%
 \label{sec:back_top}
@@ -231,23 +232,24 @@ This approach to software development is called \gls{TOSD} \citep{wang_maintaini
                The \gls{UOD} is explicitly and separately modelled by the relations that exist in the functions of the host language.
 \end{description}
 
-\Cref{fig:tosd} differs from the presented \gls{IOT} architecture because they represent separate concepts.
-The \gls{IOT} architecture from \cref{fig:iot-layers} describes an execution architecture whereas the \gls{TOSD} figure describes a software development model.
-E.g.\ from a software development perspective, a task is a task, whether it is executed on a microcontroller, a server or a client.
-Only once a task is executed, the location of the execution becomes important, but this is taken care of by the system.
+\Cref{fig:tosd} differs from the presented \gls{IOT} architecture shown in \cref{fig:iot-layers} because they represent different concepts.
+The \gls{IOT} architecture is an execution architecture whereas \gls{TOSD} is a software development model.
+E.g.\ from a software development perspective, a task is a task, whether it is executed on a microcontroller, a server, or a client.
+Only when a task is executed, the location of the execution becomes important, but this is taken care of by the system.
 Some concepts from the \gls{TOSD} model can be mapped upon the \gls{IOT} architecture though.
 Applying the concepts of \gls{TOSD} to \gls{IOT} systems can be done in two ways.
 Firstly, edge devices can be seen as simple resources, thus accessed through \glspl{SDS}.
 The second view is that edge devices contain miniature \gls{TOP} systems in itself.
 The individual components in the miniature systems, the tasks, the \glspl{SDS}, are, in the eventual execution, connected to the main system.
 
-\subsection{\texorpdfstring{\Gls{ITASK}}{ITask}}
+\subsection{The \texorpdfstring{\gls{ITASK}}{iTask} system}
 The concept of \gls{TOP} originated from the \gls{ITASK} framework, a declarative language and \gls{TOP} engine for defining interactive multi-user distributed web applications.
-\Gls{ITASK} is implemented as an \gls{EDSL} in the lazy pure \gls{FP} language \gls{CLEAN} \citep{plasmeijer_itasks:_2007,plasmeijer_task-oriented_2012}.
+The \gls{ITASK} system is implemented as an \gls{EDSL} in the lazy pure \gls{FP} language \gls{CLEAN}\footnotemark{} \citep{plasmeijer_itasks:_2007,plasmeijer_task-oriented_2012}.
+\footnotetext{\Cref{chp:clean_for_haskell_programmers} contains a guide for \gls{CLEAN} tailored to \gls{HASKELL} programmers.}
 From the structural properties of the data types and the current status of the work to be done, the entire \gls{UI} is automatically generated.
 Browsers are powering \gls{ITASK}'s presentation layer.
 The framework is built on top of standard web techniques such as JavaScript, HTML, and {CSS}.
-\Gls{ITASK} code running in the browser relies on an interpreter that operates on \gls{CLEAN}'s intermediate language \gls{ABC} \citep{staps_lazy_2019}.
+The browser runs the actual \gls{ITASK} code using an interpreter that operates on \gls{CLEAN}'s intermediate language \gls{ABC} \citep{staps_lazy_2019}.
 
 Tasks in \gls{ITASK} have either \emph{no value}, an \emph{unstable} or a \emph{stable} task value.
 For example, an editor for filling in a form initially has no value.
@@ -263,19 +265,20 @@ The allowed task value transitions are shown in \cref{fig:taskvalue}.
 \end{figure}
 
 As an example, \cref{lst:todo,fig:todo} show the code and \gls{UI} for an interactive to-do list application.
-The user can modify a shared to-do list through an editor directly or using some predefined actions.
+The user modifies a shared to-do list through an editor directly or using some predefined actions.
 Furthermore, in parallel, the length of the list is shown to demonstrate \glspl{SDS}.
 Using \gls{ITASK}, complex collaborations of users and tasks can be described on a high level.
 
 From the data type definitions (\cref{lst:todo_dt}), using generic programming (\cref{lst:todo_derive}), the \glspl{UI} for the data types are automatically generated.
-Then, using the parallel task combinator (\cleaninline{-\|\|}) that uses the left-hand side's result the task for updating the to-dos (\cref{lst:todo_update}) and the task for viewing the length are combined (\cref{lst:todo_length}).
+Then, using the parallel task combinator (\cleaninline{-\|\|}) the task for updating the to-dos (\cref{lst:todo_update}) and the task for viewing the length are combined (\cref{lst:todo_length}).
+This particular parallel combinator uses the result of the left-hand side task.
 Both tasks operate on the to-do \gls{SDS} (\cref{lst:todo_sds}).
-The task for updating the to-do list is just an editor (\cref{lst:todo_editor}) combined using a step combinator (\crefrange{lst:todo_contfro}{lst:todo_contto}).
-The actions either change the value, sorting or clearing it, or terminates the task by returning the current value of the \gls{SDS}.
+The task for updating the to-do list is an editor (\cref{lst:todo_editor}) combined using a step combinator (\crefrange{lst:todo_contfro}{lst:todo_contto}).
+The actions either change the value, sorting or clearing it, or terminate the task by returning the current value of the \gls{SDS}.
 Special combinators (e.g.\ \cleaninline{@>>} at \cref{lst:todo_ui}) are used to tweak the \gls{UI} to display informative labels.
 
-\cleaninputlisting[float=,firstline=6,lastline=22,tabsize=3,numbers=left,caption={The code for the shared to-do list in \gls{ITASK}\footnotemark.},label={lst:todo}]{lst/sharedlist.icl}
-\footnotetext{\Cref{chp:clean_for_haskell_programmers} contains a guide for \gls{CLEAN} tailored to \gls{HASKELL} programmers.}
+\cleaninputlisting[float=,firstline=6,lastline=22,tabsize=3,numbers=left,caption={The code for the shared to-do list in \gls{ITASK}.},label={lst:todo}]{lst/sharedlist.icl}
+
 \begin{figure}
        \centering
        \includegraphics[width=.75\linewidth]{todo0g}
@@ -386,7 +389,7 @@ It is compiled from the following publications:
        \item \emph{A Task-Based \glsxtrshort{DSL} for Microcomputers} \citep{koopman_task-based_2018}
                is the initial \gls{TOP}\slash{}\gls{MTASK} paper.
                It provides an overview of the initial \gls{TOP} \gls{MTASK} language and shows first versions of some interpretations.
-       \item \emph{Task Oriented Programming for the Internet of Things} \citep{lubbers_task_2018}\footnotetext{This work is an extension of my Master's thesis \citeyearpar{lubbers_task_2017}.}
+       \item \emph{Task Oriented Programming for the Internet of Things} \citep{lubbers_task_2018}\footnotetext{This work is an extension of my Master's thesis \citep{lubbers_task_2017}.}
                shows how a simple imperative variant of \gls{MTASK} was integrated with \gls{ITASK}.
                While the language was a lot different from later versions, the integration mechanism is still used in \gls{MTASK} today.
 %              \paragraph{Contribution}