slides/slides03.tex
changeset 67 ca5884c2e3bd
parent 66 3506b681c191
child 68 8da9e0c16194
--- a/slides/slides03.tex	Wed Nov 23 13:32:01 2016 +0000
+++ b/slides/slides03.tex	Thu Nov 24 01:44:38 2016 +0000
@@ -3,6 +3,7 @@
 \usepackage{../graphics}
 \usepackage{../langs}
 %\usepackage{../data}
+\usepackage[export]{adjustbox}
 
 \hfuzz=220pt 
 
@@ -18,7 +19,7 @@
 \newcommand{\bl}[1]{\textcolor{blue}{#1}}     
 
 % beamer stuff 
-\renewcommand{\slidecaption}{PEP (Scala) 02, King's College London}
+\renewcommand{\slidecaption}{PEP (Scala) 03, King's College London}
 
 
 \begin{document}
@@ -28,7 +29,7 @@
 \frametitle{%
   \begin{tabular}{@ {}c@ {}}
   \\[5mm]
-  \huge PEP Scala (2) 
+  \huge PEP Scala (3) 
   \end{tabular}}
 
   \normalsize
@@ -44,50 +45,171 @@
 \end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 
-\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Why Scala?\end{tabular}}
-
+\begin{frame}[c, fragile]
+\frametitle{The Joy of Immutability}
 
 \begin{itemize}
-\item \large {\bf You can avoid \textcolor{blue}{\texttt{null}}}:
-\end{itemize}
-
+\item If you need to manipulate some data in a list say, then you make
+  a new list with the updated values, rather than revise the original
+  list. Easy!\medskip
 
-\begin{textblock}{6}(1,5)
-  \begin{bubble}[10.5cm]\small
-      ``I call it my billion-dollar mistake. It was the invention of
-      the null reference in 1965. At that time, I was designing the
-      first comprehensive type system for references in an object
-      oriented language (ALGOL W). My goal was to ensure that all use
-      of references should be absolutely safe, with checking performed
-      automatically by the compiler. But I couldn't resist the
-      temptation to put in a null reference, simply because it was so
-      easy to implement. This has led to innumerable errors,
-      vulnerabilities, and system crashes, which have probably caused
-      a billion dollars of pain and damage in the last forty years.''
-      \hfill Sir Tony (Hoare)
-\end{bubble}
-\end{textblock}
+  {\small
+  \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
+    val old_list = List(1, 2, 3, 5)
+    val new_list = 0 :: old_list
+  \end{lstlisting}}  
   
-\begin{textblock}{5}(11.8,1)
-\includegraphics[scale=0.20]{hoare.jpg}\\
-\end{textblock}
-  
+\item You do not have to be defensive about who can access the data
+  (concurrency, lazyness).
+\end{itemize}  
 \end{frame}
 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[c]
-\frametitle{\huge\textbf{\texttt{return}}}
+\begin{frame}[t]
+\frametitle{Email: Hate 'val'}
+
+\mbox{}\\[-25mm]\mbox{}
+
+\begin{center}
+  \begin{bubble}[10.5cm]
+  Subject: \textbf{Hate '\textbf{\texttt{val}}'}\hfill 01:00 AM\medskip\\
+
+  Hello Mr Urban,\medskip\\
+
+  I just wanted to ask, how are we suppose to work
+  with the completely useless \textbf{\texttt{val}}, that can’t be changed ever? Why is
+  this rule active at all? I’ve spent 4 hours not thinking on the
+  coursework, but how to bypass this annoying rule. What’s the whole
+  point of all these coursework, when we can’t use everything Scala
+  gives us?!?\medskip\\
 
-\begin{center}\LARGE
-you should never use it
+  Regards.\\
+  \mbox{}\hspace{5mm}\textcolor{black!50}{<<deleted>>}\\
+  \end{bubble}
+\end{center}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c]
+
+\mbox{}\\[-25mm]\mbox{}
+
+\begin{center}
+  \begin{bubble}[10.5cm]
+  Subject: \textbf{Re: Hate '\textbf{\texttt{val}}'}\hfill 01:02 AM\bigskip\bigskip\\
+
+  \textcolor{black!70}{
+    \textit{\large<<my usual rant about fp\ldots\\ concurrency bla bla\ldots{} better programs
+    yada>>}}\bigskip\bigskip\bigskip
+  
+  PS: What are you trying to do where you desperately want to use \texttt{var}?
+  \end{bubble}
 \end{center}
 
 \end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c,fragile]
+
+\begin{textblock}{6}(0.5,0.5)
+\begin{bubble}[11.5cm]
+  \small  
+  Subject: \textbf{Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:04 AM\medskip\\
+
+  \textbf{Right now my is\_legal function works fine:}
+  
+\footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
+ def is_legal(dim: Int, path: Path)(x: Pos): Boolean = {
+   var boolReturn = false
+   if(x._1 > dim || x._2 > dim || x._1 < 0 || x._2 < 0) {
+   else { var breakLoop = false
+          if(path == Nil) { boolReturn = true }
+          else { for(i <- 0 until path.length) {
+                    if(breakLoop == false) {
+                      if(path(i) == x) {
+                        boolReturn = true
+                        breakLoop = true
+                      }
+                      else { boolReturn = false }
+                    } else breakLoop
+            }
+          }
+          boolReturn
+   }
+\end{lstlisting}
+\end{bubble}
+\end{textblock}
+
+\begin{textblock}{6}(8.2,11.8)
+\begin{bubble}[5.5cm]\footnotesize\bf
+\ldots{}but I can’t make it work with boolReturn being val. What approach would
+you recommend in this case, and is using var in this case justified?
+\end{bubble}
+\end{textblock}
+
+\only<2>{
+\begin{textblock}{6}(0.3,11.8)
+  \begin{bubble}[3.1cm]
+    \textbf{Me:} \includegraphics[scale=0.08, valign=t]{../pics/throwup.jpg}
+  \end{bubble}
+\end{textblock}}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[t,fragile]
+
+\mbox{}\\[-25mm]\mbox{}
+
+\begin{textblock}{6}(0.5,2)
+  \begin{bubble}[11.5cm]
+  Subject: \textbf{Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:06 AM\bigskip\\
+  \small
+  
+  OK. So you want to make sure that the \texttt{x}-position is not outside the
+  board....and furthermore you want to make sure that the \texttt{x}-position
+  is not yet in the path list. How about something like\bigskip
+
+\footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
+ def is_legal(dim: Int, path: Path)(x: Pos): Boolean = 
+ ...<<some board conditions>>... && !path.contains(x)
+\end{lstlisting}\bigskip
+  
+  \small Does not even contain a \texttt{val}.
+  \end{bubble}
+\end{textblock}
+
+\begin{textblock}{6}(7,12)
+\footnotesize\textcolor{black!50}{(This is all on one line)}
+\end{textblock}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[t,fragile]
+
+\mbox{}\\[-15mm]\mbox{}
+
+\begin{textblock}{6}(1,3)
+  \begin{bubble}[10.5cm]
+    Subject: \textbf{Re: Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 11:02 AM\bigskip\bigskip\\
+    
+    THANK YOU! You made me change my coding perspective. Because of you,
+    I figured out the next one\ldots
+  \end{bubble}
+\end{textblock}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \begin{frame}[c]
 \frametitle{Types}
 
@@ -122,11 +244,32 @@
 \end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
+
+\begin{frame}[t]
+\frametitle{Where to go on from here?}
+
+\begin{itemize}
+\item Martin Odersky (EPFL)\ldots he is currently throwing out everything
+  and starts again with the dotty compiler for Scala\medskip
+
+\item Elm (\url{http://elm-lang.org})\ldots web applications with style\medskip   
+
+\item Haskell, Ocaml, Standard ML, Scheme 
+\end{itemize}  
+\end{frame}
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \begin{frame}[c]
 \frametitle{\begin{tabular}{c}\\[3cm]\alert{Questions?}\end{tabular}}
 
-\mbox{}
+\mbox{}\footnotesize
+Thanks: ``\it{}By the way -  Scala is really getting quite fun
+when you start to get the hang of it\ldots''
+
 \end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 \end{document}