\documentclass[../thesis.tex]{subfiles}

\begin{document}
\ifSubfilesClassLoaded{
	\pagenumbering{arabic}
}{}
\chapter{Introduction}%
\label{chp:introduction}
The sheer number of connected devices around us is increasing exponentially.
First and foremost, these devices are driven by software.
This thesis is about \ldots
\todo[inline]{introduction}

\section{Internet of Things}
\todo[inline]{add more citations and rewrite to make modern}
The \gls{IOT} is growing rapidly and it is changing the way people and machines interact with the world.
While the term \gls{IOT} briefly gained interest around 1999 to describe the communication of \gls{RFID} devices~\cite{}, it probably already popped up halfway the eigthies in a speech by Peter T. Lewis~\cite{peter_t_lewis_speech_1985}.

\begin{quote}
	The \acrlong{IOT}, or \acrshort{IOT}, is the integration of people, processes and technology with connectable devices and sensors to enable remote monitoring, status, manipulation and evaluation of trends of such devices.
\end{quote}

CISCO states that the \gls{IOT} only started when there where as many connected devices as there were people on the globe, i.e.\ around 2008~\cite{evans_internet_2011}.
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.
These connected devices are already in everyone's household in the form of smart electricity meters, smart fridges, smartphones, smart watches, home automation, \etc.

When describing \gls{IOT} systems, a layered, or tiered architecture is often used to compartmentalize the technology.
The number of tiers heavily depends on the complexity of the model but for the intents and purposes of the thesis, the four layer architecture shown in \cref{fig:iot-layers} is used.

\begin{figure}[ht]
	\centering
	\includestandalone{iot-layers}
	\caption{The four layered \gls{IOT} architecture.}%
	\label{fig:iot-layers}
\end{figure}

\begin{description}
	\item[Presentation layer] This presentation layer provides the interface between the user and the \gls{IOT} application.
		For example, in home automation, this is often implemented as a web interface or a mobile app.
	\item[Application layer]
		Servers often power the application layer, by providing the data storage,
		One of its goals is to provide the \gls{API}, interfaces and data storage
	\item[Network layer] connects all layers together.
		In many applications this may be implemented using conventional networking techniques such as WiFi or wire networks.
		However, recently, networks tailored to the needs of \gls{IOT} applications have been increasingly popular such as \gls{BLE}, LoRa, ZigBee or LTE-M.
	\item[Perception layer], also called edge layer, collects the data, interacts with the environment and consists of (edge) devices equipped with various sensors and actuators.
		As a special type of device, it may also contain a \gls{SN}.
		A \gls{SN} is a collection of sensors connected by a mesh network or central hub.
\end{description}

While the number of devices seems to be growing exponentially fast, programming \gls{IOT} systems remains difficult as there is a lot of semantic friction~\cite{ireland_classification_2009}.

The devices are a large heterogeneous collection of different platforms, protocols and languages resulting in impedance problems or semantic friction between layers~\cite{ireland_classification_2009}.

Additionaly, the perception layer often is a heterogeneous collections of microcontrollers as well, each having their own peculiarities, language of choice and hardware interfaces.
The hardware needs to be cheap, small-scale and energy efficient.
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.
Typically the devices do not run a full fledged \gls{OS} but a compiled firmware.
This firmware is often written in an imperative language that needs to be flashed to the program memory.
It is possible to dynamically send the program to the program memory using \gls{OTA} programming~\cite{baccelli_scripting_2018,baccelli_reprogramming_2018}.
Program memory typically is flash based and only lasts a couple of thousand writes before it wears out.
While devices are getting a bit faster, smaller, and cheaper, they keep these properties to an extent.
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.
These problems can be mitigated by dynamically sending code to be interpreted to the \gls{MCU}.
With interpretation, a specialized interpreter is flashed in the program memory once that receives the program code to execute at runtime.

%weiser_computer_1991
\section{Domain-specific languages}
% General
Programming languages can be divided up into two categories: \glspl{DSL} and \glspl{GPL}~\cite{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 an \gls{DSL} 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.
\Glspl{DSL} come in two main flavours: standalone and embedded\footnote{Also called external and internal respectively.} of which \glspl{EDSL} can again be classified into heterogeneous and homogeneous languages (see \cref{fig:hyponymy_of_dsls} for this hyponymy).

\begin{figure}[ht]
	\centering
	\includestandalone{hyponymy_of_dsls}
	\caption{Hyponymy of \glspl{DSL} (adapted from~\cite[pg.\ 2]{mernik_extensible_2013})}%
	\label{fig:hyponymy_of_dsls}
\end{figure}

\glspl{DSL} where historically created as standalone languages which means all the 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 for the language to be usable making standalone \glspl{DSL} costly to create.
Examples of standalone \glspl{DSL} are regular expressions, make, yacc, XML, SQL, \etc.

A radically different approach is embeddding the \gls{DSL} in a host language, i.e.\ \glspl{EDSL}~\cite{hudak_modular_1998}.
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.
There are however two sides to the this coin.
If the syntax of the host language is not very flexible, the syntax of the \gls{DSL} may become clumsy.
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}.

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}:
\begin{quote}
	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.
\end{quote}
Homogeneous \glspl{EDSL} are therefore 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 \glspl{GUI} creation, LISP's macro system, \etc.

On the other hand, heterogeneous \glspl{EDSL} are languages that are not executed in the host language.
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}.
In fact, \gls{ITASK} and \gls{MTASK} are both heterogeneous \glspl{EDSL}.

\section{Functional programming}\label{ssec:functional programming}
\Gls{FP} is \ldots
\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}.

\section{Task-oriented programming}
\Gls{TOP} is a declarative programming paradigm designed to model interactive systems~\cite{plasmeijer_task-oriented_2012}.
Instead of dividing problems into layers or tiers, as is done in \gls{IOT} architectures as well, it deals with separation of concerns in a novel way.
From the data types, utilising various \emph{type-parametrised} concepts, all other aspects are handled (see \cref{fig:tosd}).
This approach to software development is also called \gls{TOSD}~\cite{wang_maintaining_2018}.

\begin{figure}[ht]
	\centering
	\begin{subfigure}[t]{.5\textwidth}
		\centering
		\includestandalone{traditional}
		\caption{Traditional layered approach.}
	\end{subfigure}%
	\begin{subfigure}[t]{.5\textwidth}
		\centering
		\includestandalone{tosd}
		\caption{\Gls{TOSD} approach.}
	\end{subfigure}
	\caption{Separation of concerns in a traditional setting and in \gls{TOSD} (adapted from~\cite[pg.\ 20]{wang_maintaining_2018}).}%
	\label{fig:tosd}
\end{figure}

\begin{description}
	\item[Presentation layer: UI]
		The \gls{UI} of the system is automatically generated from the representation of the type.
		For instance, \gls{TOP} languages implemented in an \gls{FP} language often use generic programming or template metaprogramming to automatically achieve this.
		\Gls{TOP} languages embedded in imperative programming languages may use introspection\todo{Do I want this sentence here?}.
		Even though the \gls{UI} is generated from the structure of the datatypes, in many practical \gls{TOP} systems it can be tweaked afterwards to suit the specific needs of the application.
	\item[Business layer: Tasks]
		A task is an abstract representation of a piece of work that needs to be done.
		It provides an intuitive abstraction over work in the real world.
		Just as with real-life tasks and workflow, tasks can be combined in various ways such as in parallel or in sequence.
		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.
		Examples of tasks are filling in a form, sending an email, reading a sensor or even doing a physical task.
	\item[Resource access: \glspl{SDS}]
		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.
		Tasks can also share data using \glspl{SDS}.
		\Glspl{SDS} are an abstraction over any data.
		An \gls{SDS} can represent typed data stored in a file, a chunk of memory, a database \etc.
		\Glspl{SDS} can also represent external impure data such as the time, random numbers or sensory data.
		Similar to tasks, transformation and combination of \glspl{SDS} is possible.
	\item[\Gls{UOD}: PL]
		The \gls{UOD} from the business layer is explicitly and separately modelled by the relations that exist in the functions of the host language.
		\gls{TOP} languages are usually embedded in \gls{FP} languages but this not necessarily the case.
		Some host languages also provide the implementations for the tasks and \glspl{SDS}.
		\todo{dit moet beter}
\end{description}

\section{Thesis outline}

\todo[inline]{reference correct chapters}
Chapters 0 and 0 are based on the paper \emph{A Task-Based \acrshort{DSL} for Microcomputers}~\cite{koopman_task-based_2018}.

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}.

Chapters 0 and 0 are based on the paper \emph{Multitasking on Microcontrollers using \glst{TOP}}~\cite{lubbers_multitasking_2019}.

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}.

Chapters 0 and 0 are based on the paper \emph{Interpreting \glst{TOP} Programs on Tiny Computers}~\cite{lubbers_interpreting_2019}.

Chapters 0 and 0 are based on the paper \emph{Writing \glst{IOT} applications with \glst{TOP}}~\cite{lubbers_writing_2019}.

\input{subfilepostamble}
\end{document}
