
diff -r cd2a9c969ef2 -r b8e3f32d6097 handouts/pep-ho.tex
--- a/handouts/pep-ho.tex	Fri Oct 05 11:23:15 2018 +0100
+++ b/handouts/pep-ho.tex	Fri Oct 05 11:25:53 2018 +0100
@@ -10,6 +10,22 @@
 % case class, apply, unapply
 % see https://medium.com/@thejasbabu/scala-pattern-matching-9c9e73ba9a8a
 
+% the art of programming
+% https://www.youtube.com/watch?v=QdVFvsCWXrA
+
+% functional programming in Scala
+%https://www.amazon.com/gp/product/1449311032/ref=as_li_ss_tl?ie=UTF8&tag=aleottshompag-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=1449311032
+
+% functional programmming in C
+%https://www.amazon.com/gp/product/0201419505/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=0201419505&linkCode=as2&tag=aleottshompag-20
+
+%speeding through haskell
+%https://openlibra.com/en/book/download/speeding-through-haskell
+
+% fp books --- ocaml
+% http://courses.cms.caltech.edu/cs134/cs134b/book.pdf
+% http://alexott.net/en/fp/books/
+
 \begin{document}
 \fnote{\copyright{} Christian Urban, King's College London, 2017, 2018}
 
@@ -36,8 +52,8 @@
 ``Scala is the better Java''.\footnote{from
 \url{https://www.slideshare.net/maximnovak/joy-of-scala}} 
 
-A number of companies---the Guardian, Twitter, Coursera, FourSquare, Netflix,
-LinkedIn to name a few---either use Scala exclusively in
+A number of companies---the Guardian, Twitter, Coursera, FourSquare,
+Netflix, LinkedIn, ITV to name a few---either use Scala exclusively in
 production code, or at least to some substantial degree. Scala seems
 also useful in job-interviews (especially in data science) according to
 this anecdotal report
@@ -51,12 +67,18 @@
 
 \begin{quote}
 \url{http://www.scala-lang.org}
-\end{quote}
+\end{quote} 
 
 \noindent
 I found a convenient IDE for writing Scala programs is Microsoft's
 \textit{Visual Studio Code} (VS Code) which runs under MacOSX, Linux and
-obviously Windows. It can be downloaded for free from
+obviously Windows.\footnote{Unlike \emph{Microsoft Visual Studio}---note
+the minuscule difference in the name---which is a heavy-duty,
+Windows-only IDE\ldots{}jeez, with all their money could they not come
+up with a completely different name for a complete different project?
+For the pedantic, Microsoft Visual Studio is an IDE, whereas Visual
+Studio Code is a source code editor. Anybody knows the what the
+difference is?} It can be downloaded for free from
 
 \begin{quote}
 \url{https://code.visualstudio.com}
@@ -64,7 +86,8 @@
 
 \noindent
 and should already come pre-installed in the Department (together with
-the Scala compiler). VS Code is far from perfect, however it includes a
+the Scala compiler). Being a project started in 2015, VS Code is
+relatively new and thus far from perfect. However it includes a
 \textit{Marketplace} from which a multitude of extensions can be
 downloaded that make editing and running Scala code a little easier (see
 Figure~\ref{vscode} for my setup).
@@ -105,8 +128,8 @@
 \end{quote}
 
 \noindent
-Also IntelliJ includes plugins for Scala. \textbf{BUT}, I do \textbf{not}
-recommend the usage of either Eclipse or IntelliJ for PEP: these IDEs
+Also IntelliJ includes plugins for Scala. \underline{\textbf{BUT}}, 
+I do \textbf{not} recommend the usage of either Eclipse or IntelliJ for PEP: these IDEs
 seem to make your life harder, rather than easier, for the small
 programs we will write in this module. They are really meant to be used
 when you have a million-lines codebase, rather than our
@@ -136,10 +159,10 @@
 programming seems to go against the core principles of
 \textit{imperative programming} (which is what you do in Java and C++
 for example). The main idea of imperative programming  is that you have
-some form of ``state'' in your program and you continuously change this
-state by issuing some commands (e.g.~updating a field in an array or
-object, adding one to a variable and so on). The classic example for
-this style of programming are \texttt{for}-loops, for example
+some form of \emph{state} in your program and you continuously change this
+state by issuing some commands---for example for updating a field in an
+array or object, or for adding one to a variable and so on. The classic
+example for this style of programming are \texttt{for}-loops, like
 
 \begin{lstlisting}[language=C,numbers=none]
 for (int i = 10; i < 20; i++) { 
@@ -153,10 +176,10 @@
 exits. When this code is compiled and actually runs, there will be some
 dedicated space reserved for \texttt{i} in memory. This space of
 typically 32 bits contains \texttt{i}'s current value\ldots\texttt{10}
-at the beginning, and then the content will be updated by, or
-overwritten with, some new content in every iteration. The main point
-here is that this kind of updating, or manipulating, memory is
-25.806\ldots or \textbf{THE ROOT OF ALL EVIL}!!
+at the beginning, and then the content will be overwritten with some
+new content in every iteration. The main point here is that this kind of
+updating, or manipulating, memory is 25.806\ldots or \textbf{THE ROOT OF
+ALL EVIL}!!
 
 \begin{center}
 \includegraphics[scale=0.25]{../pics/root-of-all-evil.png}
@@ -200,7 +223,7 @@
 
 The central idea of functional programming is to eliminate any state
 from programs---or at least from the ``interesting bits''. Because then
-it is easy to parallelize the resulting programs: if you do not have any
+it is easy to parallelise the resulting programs: if you do not have any
 state, then once created, all memory content stays unchanged and reads
 to such memory are absolutely safe without the need of any
 synchronisation. An example is given in Figure~\ref{mand} where in the
@@ -216,21 +239,21 @@
 \begin{figure}[p]
 \begin{boxedminipage}{\textwidth}
 
-A Scala program for generating pretty pictures of the Mandelbrot set 
-(\url{https://en.wikipedia.org/wiki/Mandelbrot_set},
-\url{https://www.youtube.com/watch?v=aSg2Db3jF_4}):
+A Scala program for generating pretty pictures of the Mandelbrot set.\smallskip\\ 
+(See \url{https://en.wikipedia.org/wiki/Mandelbrot_set} or\\
+\phantom{(See }\url{https://www.youtube.com/watch?v=aSg2Db3jF_4}):
 \begin{center}    
 \begin{tabular}{c}  
-\includegraphics[scale=0.12]{../pics/mand1.png}
+\includegraphics[scale=0.11]{../pics/mand1.png}\\[-8mm]\mbox{}
 \end{tabular}
 \end{center}
 
 \begin{center}
 \begin{tabular}{@{}p{0.45\textwidth}|p{0.45\textwidth}@{}}
-  \bf sequential version: & \bf parallel version (on 4 cores):\smallskip\\
+  \bf sequential version: & \bf parallel version on 4 cores:\smallskip\\
 
-  {\hfill\includegraphics[scale=0.12]{../pics/mand4.png}\hfill} &
-  {\hfill\includegraphics[scale=0.12]{../pics/mand3.png}\hfill} \\
+  {\hfill\includegraphics[scale=0.11]{../pics/mand4.png}\hfill} &
+  {\hfill\includegraphics[scale=0.11]{../pics/mand3.png}\hfill} \\
 
 {\footnotesize\begin{lstlisting}[xleftmargin=-1mm]
 for (y <- (0 until H)) {
@@ -239,11 +262,11 @@
     val c = start + 
       (x * d_x + y * d_y * i)
     val iters = iterations(c, max) 
-    val col = 
+    val colour = 
       if (iters == max) black 
       else colours(iters % 16)
 
-    pixel(x, y, col)
+    pixel(x, y, colour)
   }
   viewer.updateUI()
 }   
@@ -256,25 +279,28 @@
     val c = start + 
       (x * d_x + y * d_y * i)
     val iters = iterations(c, max) 
-    val col = 
+    val colour = 
       if (iters == max) black 
       else colours(iters % 16)
   
-    pixel(x, y, col)
+    pixel(x, y, colour)
   }
   viewer.updateUI()
 }   
-\end{lstlisting}}\\
+\end{lstlisting}}\\[-2mm]
 
 \centering\includegraphics[scale=0.5]{../pics/cpu2.png} &
 \centering\includegraphics[scale=0.5]{../pics/cpu1.png}
 \end{tabular}
 \end{center}
-\caption{The main ``loops'' creating the picture of the Mandelbrot set. The parallel version
-only differs in \texttt{.par} added to the ``ranges'' of the x-y-coordinates. As can be
-seen from the CPU loads: in the sequential versions there is a lower peak for an
-extended period, while in the parallel version there is a short sharp burst for 
-essentially the same workload.
+\caption{The ``main'' loops in the Mandelbrot program.
+The parallel version differs only in \texttt{.par} being added to the
+``ranges'' of the x-y-coordinates. As can be seen from the CPU loads, in
+the sequential versions there is a lower peak for an extended period,
+while in the parallel version there is a short sharp burst for
+essentially the same workload\ldots{}meaning you get more work done 
+in a shorter amount of time. This \emph{parallelisation} 
+only works reliably in an immutable program.
 \label{mand}} 
 \end{boxedminipage}
 \end{figure}  
@@ -292,10 +318,11 @@
 programming ``thing'', there are a few more arguments: a lot of research
 in programming languages happens to take place in functional programming
 languages. This has resulted in ultra-useful features such as
-pattern-matching, strong type-systems, lazyness, implicits, algebraic
+pattern-matching, strong type-systems, laziness, implicits, algebraic
 datatypes  to name a few. Imperative languages seem to often lag behind
 in adopting them: I know, for example, that Java will at some point in
-the future support pattern-matching, which has been used in SML for at
+the future support pattern-matching, which has been used for example 
+in SML for at
 least 40(!) years. See
 \url{http://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html}.
 Also Rust, a C-like programming language that has been developed since
@@ -1133,15 +1160,15 @@
   \url{http://scalapuzzlers.com} and
   \url{http://latkin.org/blog/2017/05/02/when-the-scala-compiler-doesnt-help/}
 \end{center}
-
-Even if Scala has been a success in several high-profile
-companies, there is also a company (Yammer) that first used
-Scala in their production code, but then moved away from it.
-Allegedly they did not like the steep learning curve of Scala
-and also that new versions of Scala often introduced
-incompatibilities in old code. In the past two months
-there have also been two forks of the Scala compiler.
-It needs to be seen what the future brings for Scala.
+     
+Even if Scala has been a success in several high-profile companies,
+there is also a company (Yammer) that first used Scala in their
+production code, but then moved away from it. Allegedly they did not
+like the steep learning curve of Scala and also that new versions of
+Scala often introduced incompatibilities in old code. Also the Java
+language is lately developing at lightening speed taking on many
+features of Scala and other languages, and it seems even it introduces
+new features on its own.
 
 %So all in all, Scala might not be a great teaching language,
 %but I hope this is mitigated by the fact that I never require
@@ -1152,6 +1179,14 @@
 %with.
 
 
+\subsection*{Conclusion}
+
+\begin{itemize}
+\item no exceptions....there two kinds, one ``global'' exceptions, like
+out of memory (not much can be done about this by the ``individual''
+programmer); and ``local one'' open a file that might not exists - in
+the latter you do not want to use exceptions, but Options
+\end{itemize}
 
 \begin{flushright}\it
 There are only two kinds of languages: the ones people complain 




