handouts/pep-ho.tex
changeset 195 fc3ac7b70a06
parent 193 ae307c3de4ee
child 197 c3e39fdeea3b
--- a/handouts/pep-ho.tex	Fri Oct 05 11:27:16 2018 +0100
+++ b/handouts/pep-ho.tex	Sat Nov 03 11:07:44 2018 +0000
@@ -34,19 +34,17 @@
 \mbox{}\hfill\textit{``Scala --- \underline{S}lowly \underline{c}ompiled 
 \underline{a}cademic \underline{la}nguage''}\smallskip\\
 \mbox{}\hfill\textit{ --- a joke(?) found on Twitter}\bigskip
- 
+
+
+\subsection*{Introduction}
+
 \noindent
 Scala is a programming language that combines functional and
 object-oriented programming-styles. It has received quite a bit of
 attention in the last five or so years. One reason for this attention is
 that, like the Java programming language, Scala compiles to the Java
 Virtual Machine (JVM) and therefore Scala programs can run under MacOSX,
-Linux and Windows.\footnote{There are also experimental backends of
-Scala for producing code under Android (\url{http://scala-android.org});
-for generating JavaScript code to build browser applications
-\url{(https://www.scala-js.org)}; and there is work under way to
-have a native Scala compiler generating X86-code
-(\url{http://www.scala-native.org}).} Because of this it has also access to
+Linux and Windows. Because of this it has also access to
 the myriads of Java libraries. Unlike Java, however, Scala often allows
 programmers to write very concise and elegant code.  Some therefore say
 ``Scala is the better Java''.\footnote{from
@@ -66,10 +64,19 @@
 The official Scala compiler can be downloaded from
 
 \begin{quote}
-\url{http://www.scala-lang.org}
-\end{quote} 
+\url{http://www.scala-lang.org}\medskip
+\end{quote}
 
 \noindent
+If you are interested there are also experimental backends of Scala
+for producing code under Android (\url{http://scala-android.org}); for
+generating JavaScript code (\url{https://www.scala-js.org}); and there
+is work under way to have a native Scala compiler generating X86-code
+(\url{http://www.scala-native.org}). Though be warned these backends
+are still rather beta or even alpha.
+
+\subsection*{VS Code and Scala}
+
 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.\footnote{Unlike \emph{Microsoft Visual Studio}---note
@@ -86,7 +93,7 @@
 
 \noindent
 and should already come pre-installed in the Department (together with
-the Scala compiler). Being a project started in 2015, VS Code is
+the Scala compiler). Being a project that just 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
@@ -97,12 +104,13 @@
 \begin{center}  
 \includegraphics[scale=0.15]{../pics/vscode.png}\\[-10mm]\mbox{}
 \end{center}
-\caption{My personal installation of VS Code includes the following
-packages from Marketplace: Scala Syntax (official), Code Runner, Code
-Spell Checker, Rewrap and Subtle Match Brackets. I have also bound 
-the keys \keys{Ctrl} \keys{Ret} to the action
-``Run-Selected-Text-In-Active-Terminal'' in order to quickly evaluate
-small code snippets in the Scala REPL.\label{vscode}}
+\caption{My installation of VS Code includes the following
+  packages from Marketplace: \textbf{Scala Syntax (official)} 0.2.0,
+  \textbf{Code Runner} 0.9.5, \textbf{Code Spell Checker} 1.6.10,
+  \textbf{Rewrap} 1.9.1 and \textbf{Subtle Match
+  Brackets} 3.0.0. I have also bound the keys \keys{Ctrl} \keys{Ret} to the
+  action ``Run-Selected-Text-In-Active-Terminal'' in order to quickly
+  evaluate small code snippets in the Scala REPL.\label{vscode}}
 \end{boxedminipage}
 \end{figure}  
 
@@ -110,16 +118,18 @@
 Scala REPL. But if you prefer another editor for coding, it is also
 painless to work with Scala completely on the command line (as you might
 have done with \texttt{g++} in the earlier part of PEP). For the
-lazybones among us, there is even an online editor and environment for
-developing and running Scala programs called \textit{ScalaFiddle}, which
-requires zero setup (assuming you have a browser handy). You can access
-it from: 
+lazybones among us, there are even online editors and environments for
+developing and running Scala programs called \textit{ScalaFiddle}
+and \textit{Scastie}, which
+require zero setup (assuming you have a browser handy). You can access
+them from: 
  
 \begin{quote}
-\url{https://scalafiddle.io}\medskip
+  \url{https://scalafiddle.io}\\
+  \url{https://scastie.scala-lang.org}\medskip
 \end{quote}
   
-
+\noindent
 Scala can be used with the heavy-duty IDEs Eclipse and IntelliJ.
 A ready-made Scala bundle for Eclipse is available from
 
@@ -222,19 +232,20 @@
 being able to debug such code.
 
 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 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
-absence of the annoying state, Scala makes it very easy to calculate the
-Mandelbrot set on as many cores of your CPU as possible. Why is it so
-easy in this example? Because each pixel in the Mandelbrot set can be
-calculated independently and the calculation does not need to update any
-variable. It is so easy in fact that going from the sequential version
-of the Mandelbrot program to the parallel version can be achieved by
-adding just eight characters---in two places you have to add
-\texttt{.par}. Try the same in C++ or Java!
+from programs---or at least from the ``interesting bits'' of the
+programs. Because then 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 absence of the annoying state, Scala
+makes it very easy to calculate the Mandelbrot set on as many cores of
+your CPU as possible. Why is it so easy in this example? Because each
+pixel in the Mandelbrot set can be calculated independently and the
+calculation does not need to update any variable. It is so easy in
+fact that going from the sequential version of the Mandelbrot program
+to the parallel version can be achieved by adding just eight
+characters---in two places you have to add \texttt{.par}. Try the same
+in C++ or Java!
 
 \begin{figure}[p]
 \begin{boxedminipage}{\textwidth}
@@ -293,14 +304,14 @@
 \centering\includegraphics[scale=0.5]{../pics/cpu1.png}
 \end{tabular}
 \end{center}
-\caption{The ``main'' loops in the Mandelbrot program.
+\caption{The code of the ``main'' loops in my 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,
+``ranges'' of the x and y coordinates. As can be seen from the CPU loads, in
+the sequential version 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.
+in a shorter amount of time. This easy \emph{parallelisation} 
+only works reliably with an immutable program.
 \label{mand}} 
 \end{boxedminipage}
 \end{figure}  
@@ -343,7 +354,7 @@
 
 \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
 $ scala
-Welcome to Scala 2.12.6 (Java HotSpot(TM) 64-Bit Server VM, Java 9).
+Welcome to Scala 2.12.7 (Java HotSpot(TM) 64-Bit Server VM, Java 9).
 Type in expressions for evaluation. Or try :help.
 
 scala>
@@ -481,7 +492,7 @@
 
 \noindent
 So it would be a bit absurd to call values as variables...you cannot
-change them; they cannot vary. You might think you can re-assign them like
+change them; they cannot vary. You might think you can reassign them like
 
 \begin{lstlisting}[numbers=none]
 scala> val x = 42
@@ -533,8 +544,8 @@
 function, \code{rty}, should be given. If the body of the function is
 more complex, then it can be enclosed in braces, like above. If it it
 is just a simple expression, like \code{x + 1}, you can omit the
-braces. Very often functions are recursive (call themselves) like
-the venerable factorial function:
+braces. Very often functions are recursive (that is call themselves),
+like the venerable factorial function:
 
 \begin{lstlisting}[numbers=none]
 def fact(n: Int): Int = 
@@ -734,12 +745,12 @@
 important role. Scala is such a language. You have already
 seen built-in types, like \code{Int}, \code{Boolean},
 \code{String} and \code{BigInt}, but also user-defined ones,
-like \code{Rexp}. Unfortunately, types can be a thorny
+like \code{Rexp} (see coursework). Unfortunately, types can be a thorny
 subject, especially in Scala. For example, why do we need to
 give the type to \code{toSet[Int]}, but not to \code{toList}?
 The reason is the power of Scala, which sometimes means it
 cannot infer all necessary typing information. At the
-beginning while getting familiar with Scala, I recommend a
+beginning, while getting familiar with Scala, I recommend a
 ``play-it-by-ear-approach'' to types. Fully understanding
 type-systems, especially complicated ones like in Scala, can
 take a module on their own.\footnote{Still, such a study can
@@ -1111,6 +1122,8 @@
 
 \subsection*{Coursework}
 
+
+
 \subsection*{More Info}
 
 There is much more to Scala than I can possibly describe in