stab at some chapters
[phd-thesis.git] / introduction.tex
1 The sheer number of connected devices around us is increasing exponentially.
2 First and foremost, these devices are driven by software.
3 This thesis is about \ldots
4 \todo[inline]{introduction}
5
6 \section{\Acrlong{IOT}}
7 \todo[inline]{add more citations and rewrite to make modern}
8 The \gls{IOT} is growing rapidly and it is changing the way people and machines interact with the world.
9 The term \gls{IOT} was coined around 1999 to describe the communication of \gls{RFID} devices.
10 \gls{RFID} became more and more popular the years after but the term \gls{IOT} was not associated with it anymore.
11 Years later, during the rise of novel network technologies, the term \gls{IOT} resurged with a slightly different meaning.
12 Today, the \gls{IOT} is the term for a system of devices that sense the environment, act upon it and communicate with each other and the world.
13 At the time of writing, there is about one connected device per person in the world of which many are part of an \gls{IOT} system.
14 Gartner estimates that of these connected devices, there are about $5.8$ billion \gls{IOT} devices or endpoints connected~\footnote{Gartner (August 2019)}\todo[inline]{update with recent number}.
15 They are already in everyone's household in the form of smart electricity meters, smart fridges, smartphones, smart watches, home automation and in the form of much more.
16 While the number of devices seems to be growing exponentially fast, programming \gls{IOT} applications is difficult.
17 The devices are a large heterogeneous collection of different platforms, protocols and languages resulting in impedance problems.
18
19 The devices in \gls{IOT} systems are equipped with various sensors and actuators.
20 These range from external ones such as positioning, temperature and humidity to more internal ones like heartbeat and respiration.
21 When describing \gls{IOT} systems, a layered architecture is often used to compartmentalize the technology.
22 For the intents and purposes of this paper the four layer architecture defined by ITU-T (International Telecommunications Union {-} Telecommunication Standardization Sector) will be used as visualized in Figure~\ref{fig:layers}.
23
24 \begin{figure}
25 \centering
26 \begin{tikzpicture}[node distance=3em]
27 \node (1) [rectangle,draw,minimum width=10em] {Application Layer};
28 \node (2) [rectangle,draw,minimum width=10em,below of=1] {Support Laper};
29 \node (3) [rectangle,draw,minimum width=10em,below of=2] {Network Layer};
30 \node (4) [rectangle,draw,minimum width=10em,below of=3] {Perception Layer};
31
32 \draw [->] (1) -- (2);
33 \draw [->] (2) -- (1);
34 \draw [->] (2) -- (3);
35 \draw [->] (3) -- (2);
36 \draw [->] (3) -- (4);
37 \draw [->] (4) -- (3);
38 \end{tikzpicture}
39 \caption{The four layered \gls{IOT} architecture as described by the ITU-T.}%
40 \label{fig:layers}
41 \end{figure}
42
43 The first layer is called the perception layer and contains the actual endpoints with their peripherals.
44 For example in home automation, the sensors reading the room and the actuators opening the curtains are in the perception layer.
45 As a special type of device, it may also contain a \gls{SN}.
46 A \gls{SN} is a collection of sensors connected by a mesh network or central hub.
47 The network layer is the second layer and it consists of the hardware and software to connect the perception layer to the world.
48 In home automation, this layer may consist of a specialized \gls{IOT} technology such as \gls{BLE} or ZigBee but it may also use existing technologies such as WiFi or wired connections.
49 The third layer is named support layer and is responsible for the servicing and business rules surrounding the application.
50 One of its goals is to provide the \gls{API}, interfaces and data storage.
51 In home automation this provides the server storing the data.
52 The fourth and final layer in this architecture is the application layer.
53 The application layer provides the interaction between the user and the \gls{IOT} system.
54 In home automation, this layer contains the apps for to read the measurements and control the devices.
55
56 The perception layer often is a heterogeneous collections of microcontrollers, each having their own peculiarities, language of choice and hardware interfaces.
57 The hardware needs to be cheap, small-scale and energy efficient.
58 As a result, the \glspl{MCU} used to power these devices do not have a lot of computational power, a soup\c{c}on of memory, and little communication bandwidth.
59 Typically the devices do not run a full fledged \gls{OS} but a compiled firmware.
60 This firmware is often written in an imperative language that needs to be flashed to the program memory.
61 It is possible to dynamically send the program to the program memory using \gls{OTA} programming~\cite{baccelli_scripting_2018,baccelli_reprogramming_2018}.
62 Program memory typically is flash based and only lasts a couple of thousand writes before it wears out.
63 While devices are getting a bit faster, smaller, and cheaper, they keep these properties to an extent.
64 The properties of the device greatly reduce the flexibility for dynamic systems where tasks are created on the fly, executed on demand and require parallel execution.
65 These problems can be mitigated by dynamically sending code to be interpreted to the \gls{MCU}.
66 With interpretation, a specialized interpreter is flashed in the program memory once that receives the program code to execute at runtime.
67
68 \section{\Acrlongpl{DSL}}
69 % General
70 Programming languages can be divided up into two categories: \glspl{DSL} and \glspl{GPL}\todo{citation needed}.
71 Where \glspl{GPL} are not made with a demarcated area in mind, \glspl{DSL} are tailor-made for a specific domain.
72 Consequently, writing idiomatic domain-specific code is easy but this may come at the cost of the \gls{DSL} being less expressive to an extent that it may not even be Turing complete.
73 \Glspl{DSL} come in two main flavours: standalone and embedded\footnote{Also called external and internal respectively~\cite{fowler_domain-specific_2010}} of which \glspl{EDSL} can again be classified into heterogeneous and homogeneous languages (see \cref{fig:taxonomy_of_dsls} for this taxonomy).
74
75 \begin{figure}[ht]
76 \centering
77 \begin{tikzpicture}[nodes={draw,minimum width=7.5em}]
78 \node (dsl) {\gls{DSL}};
79 \node (sta) [below=of dsl,xshift=-3.75em] {standalone};
80 \node (emb) [right=of sta] {embedded};
81 \node (het) [below=of emb,xshift=-3.75em] {heterogeneous};
82 \node (hom) [right=of het] {homogeneous};
83 \draw [->] (dsl) -- (sta);
84 \draw [->] (dsl) -- (emb);
85 \draw [->] (emb) -- (het);
86 \draw [->] (emb) -- (hom);
87 \end{tikzpicture}
88 \caption{Taxonomy of \glspl{DSL} (adapted from Verna~\cite[pg.\ 2]{mernik_extensible_2013})}%
89 \label{fig:taxonomy_of_dsls}
90 \end{figure}
91
92 DSLs where historically created as standalone languages which means all the machinery is developed solely for the language.
93 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.
94 Unfortunately it also means that they need to develop a compiler or interpreter for the language to be usable making standalone \glspl{DSL} costly to create.
95 Examples of standalone \glspl{DSL} are regular expressions, make, yacc, XML, SQL, \etc.
96
97 A radically different approach is embeddding the \gls{DSL} in a host language, i.e.\ \glspl{EDSL}~\cite{hudak_modular_1998}.
98 By defining the language as constructs in the host language, much of the machinery is inherited and the cost of creating embedded languages is very low.
99 There are however two sides to the this coin.
100 If the syntax of the host language is not very flexible, the syntax of the \gls{DSL} may become clumsy.
101 Furthermore, 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}.
102
103 Tratt applied a notion from metaprogramming~\cite{sheard_accomplishments_2001} to \glspl{EDSL} to define homogeneity and heterogeneity of \glspl{EDSL} as follows~\cite{tratt_domain_2008}:
104 \begin{quote}
105 a homogeneous system is one where all the components are specifically designed to work with each other, whereas in heterogeneous systems at least one of the components is largely, or completely, ignorant of the existence of the other parts of the system.
106 \end{quote}
107 Homogeneous \glspl{EDSL} are therefore languages that are solely defined as an extension to their host language.
108 They often restrict features of the host language to provide a safer interface or capture an idiomatic pattern in the host language for reuse.
109 The difference between a library and a homogeneous \glspl{EDSL} is not always clear.
110 Examples of homogeneous \glspl{EDSL} are libraries such as ones for \glspl{GUI} creation, LISP's macro system, \etc.
111
112 On the other hand, heterogeneous \glspl{EDSL} are languages that are not executed in the host language.
113 For example, Elliott et al.\ 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~\cite{elliott_compiling_2003}.
114 In fact, \gls{ITASK} and \gls{MTASK} are both heterogeneous \glspl{EDSL}.
115
116 \section{\Acrlong{FP}}\label{ssec:functional programming}
117 \Gls{FP} is \ldots
118 \Gls{FP} languages are naturally suitable as a host language for \gls{DSL} embedding because of their rich type systems and minimal and extensible syntax~\cite{gibbons_functional_2015}.
119
120 \section{\Acrlong{TOP}}
121 \Gls{TOP} is a declarative programming paradigm designed to model interactive systems~\cite{plasmeijer_task-oriented_2012}.
122 Instead of dividing problems up into a layered approach it deals with separation of concerns in a novel way (see \cref{fig:tosd}).
123 All components of a \gls{TOP} program are centered around the data types and from these datatypes, implementation details such as the interface, the communication and the sharing of data is generated.
124 \begin{description}
125 \item[Data types]
126 In \gls{TOP}, everything is based around datatypes.
127 \item[Tasks]
128 A task is an abstract representation of a piece of work that needs to be done.
129 It provides an intuitive abstraction over work in the real world.
130 Just as with real-life tasks and workflow, tasks can be combined in various ways such as in parallel or in sequence.
131 Furthermore, tasks are observable which means it is possible to observe a --- partial --- result during execution and act upon it by for example starting new tasks.
132 Examples of tasks are filling in a form, sending an email, reading a sensor or even doing a physical task.
133 \item[UI]
134 The \gls{UI} of the system is automatically generated from the representation of the type.
135 For example, in \gls{FP} languages this may be done using generic programming or template metaprogramming whereas in imperative programming languages they may be done using introspection\todo{Do I want this sentence here?}.
136 In many practical \gls{TOP} systems the \gls{UI} can be tweaked afterwards to suit the needs of the application.
137 \item[SDS]
138 Tasks can communicate using task values but this imposes a problem in many collaboration patterns where tasks that are not necessarily related need to share data.
139 Tasks can also share data using \glspl{SDS}.
140 \Glspl{SDS} are an abstraction over any data.
141 An \gls{SDS} can represent typed data stored in a file, a chunk of memory, a database \etc.
142 \Glspl{SDS} can also represent external impure data such as the time, random numbers or sensory data.
143 Similar to tasks, transformation and combination of \glspl{SDS} is possible.
144 \item[PL]
145 \gls{TOP} languages are usually embedded in \gls{FP} languages but not necessarily.
146 The languages in which the \gls{TOP} is hosted provides the integration with the execution platform if there is any.
147 Some host languages also provide the implementations for the tasks and \glspl{SDS}.
148 \end{description}
149
150 \begin{figure}[ht]
151 \centering
152 \begin{tikzpicture}
153 \pie[%
154 color={red,violet,teal,blue},
155 explode={0.1},
156 hide number,
157 text=inside,
158 rotate=45,
159 radius=2.25,
160 ]{%
161 25/\textcolor{white}{UI},
162 25/\textcolor{white}{Tasks},
163 25/\textcolor{white}{PL},
164 25/\textcolor{white}{SDS}
165 }
166 \node [draw,fill=yellow,circle]{Types};
167 \end{tikzpicture}
168 \caption{\Gls{TOSD} approach (adapted from Stutterheim et al.~\cite[pg.\ 20]{wang_maintaining_2018})}%
169 \label{fig:tosd}
170 \end{figure}
171
172 \section{Thesis Outline}
173
174 \todo[inline]{reference correct chapters}
175 Chapters 0 and 0 are based on the paper \emph{A Task-Based \acrshort{DSL} for Microcomputers}~\cite{koopman_task-based_2018}.
176
177 Chapters 0 and 0 are based on the Master's thesis and paper \emph{\glst{TOP} and the \glst{IOT}}~\cite{lubbers_task_2017,lubbers_task_2018}.
178
179 Chapters 0 and 0 are based on the paper \emph{Multitasking on Microcontrollers using \glst{TOP}}~\cite{lubbers_multitasking_2019}.
180
181 Chapters 0 and 0 are based on the paper \emph{Tiered versus Tierless \acrshort{IOT} Stacks: Comparing Smart Campus Software Architectures}~\cite{lubbers_tiered_2020}.
182
183 Chapters 0 and 0 are based on the paper \emph{Interpreting \glst{TOP} Programs on Tiny Computers}~\cite{lubbers_interpreting_2019}.
184
185 Chapters 0 and 0 are based on the paper \emph{Writing \glst{IOT} applications with \glst{TOP}}~\cite{lubbers_writing_2019}.