slides/slides03.tex
changeset 67 ca5884c2e3bd
parent 66 3506b681c191
child 68 8da9e0c16194
equal deleted inserted replaced
66:3506b681c191 67:ca5884c2e3bd
     1 \documentclass[dvipsnames,14pt,t,xelatex]{beamer}
     1 \documentclass[dvipsnames,14pt,t,xelatex]{beamer}
     2 \usepackage{../slides}
     2 \usepackage{../slides}
     3 \usepackage{../graphics}
     3 \usepackage{../graphics}
     4 \usepackage{../langs}
     4 \usepackage{../langs}
     5 %\usepackage{../data}
     5 %\usepackage{../data}
       
     6 \usepackage[export]{adjustbox}
     6 
     7 
     7 \hfuzz=220pt 
     8 \hfuzz=220pt 
     8 
     9 
     9 %\setmonofont[Scale=.88]{Consolas}
    10 %\setmonofont[Scale=.88]{Consolas}
    10 %\newfontfamily{\consolas}{Consolas}
    11 %\newfontfamily{\consolas}{Consolas}
    16         xleftmargin=0mm}
    17         xleftmargin=0mm}
    17 
    18 
    18 \newcommand{\bl}[1]{\textcolor{blue}{#1}}     
    19 \newcommand{\bl}[1]{\textcolor{blue}{#1}}     
    19 
    20 
    20 % beamer stuff 
    21 % beamer stuff 
    21 \renewcommand{\slidecaption}{PEP (Scala) 02, King's College London}
    22 \renewcommand{\slidecaption}{PEP (Scala) 03, King's College London}
    22 
    23 
    23 
    24 
    24 \begin{document}
    25 \begin{document}
    25 
    26 
    26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    27 \begin{frame}[t]
    28 \begin{frame}[t]
    28 \frametitle{%
    29 \frametitle{%
    29   \begin{tabular}{@ {}c@ {}}
    30   \begin{tabular}{@ {}c@ {}}
    30   \\[5mm]
    31   \\[5mm]
    31   \huge PEP Scala (2) 
    32   \huge PEP Scala (3) 
    32   \end{tabular}}
    33   \end{tabular}}
    33 
    34 
    34   \normalsize
    35   \normalsize
    35   \begin{center}
    36   \begin{center}
    36   \begin{tabular}{ll}
    37   \begin{tabular}{ll}
    42 
    43 
    43 
    44 
    44 \end{frame}
    45 \end{frame}
    45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
    46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
    46 
    47 
       
    48 \begin{frame}[c, fragile]
       
    49 \frametitle{The Joy of Immutability}
       
    50 
       
    51 \begin{itemize}
       
    52 \item If you need to manipulate some data in a list say, then you make
       
    53   a new list with the updated values, rather than revise the original
       
    54   list. Easy!\medskip
       
    55 
       
    56   {\small
       
    57   \begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
       
    58     val old_list = List(1, 2, 3, 5)
       
    59     val new_list = 0 :: old_list
       
    60   \end{lstlisting}}  
       
    61   
       
    62 \item You do not have to be defensive about who can access the data
       
    63   (concurrency, lazyness).
       
    64 \end{itemize}  
       
    65 \end{frame}
       
    66 
       
    67 
       
    68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    47 \begin{frame}[t]
    69 \begin{frame}[t]
    48 \frametitle{\begin{tabular}{c}Why Scala?\end{tabular}}
    70 \frametitle{Email: Hate 'val'}
    49 
    71 
    50 
    72 \mbox{}\\[-25mm]\mbox{}
    51 \begin{itemize}
    73 
    52 \item \large {\bf You can avoid \textcolor{blue}{\texttt{null}}}:
    74 \begin{center}
    53 \end{itemize}
    75   \begin{bubble}[10.5cm]
    54 
    76   Subject: \textbf{Hate '\textbf{\texttt{val}}'}\hfill 01:00 AM\medskip\\
    55 
    77 
    56 \begin{textblock}{6}(1,5)
    78   Hello Mr Urban,\medskip\\
    57   \begin{bubble}[10.5cm]\small
    79 
    58       ``I call it my billion-dollar mistake. It was the invention of
    80   I just wanted to ask, how are we suppose to work
    59       the null reference in 1965. At that time, I was designing the
    81   with the completely useless \textbf{\texttt{val}}, that can’t be changed ever? Why is
    60       first comprehensive type system for references in an object
    82   this rule active at all? I’ve spent 4 hours not thinking on the
    61       oriented language (ALGOL W). My goal was to ensure that all use
    83   coursework, but how to bypass this annoying rule. What’s the whole
    62       of references should be absolutely safe, with checking performed
    84   point of all these coursework, when we can’t use everything Scala
    63       automatically by the compiler. But I couldn't resist the
    85   gives us?!?\medskip\\
    64       temptation to put in a null reference, simply because it was so
    86 
    65       easy to implement. This has led to innumerable errors,
    87   Regards.\\
    66       vulnerabilities, and system crashes, which have probably caused
    88   \mbox{}\hspace{5mm}\textcolor{black!50}{<<deleted>>}\\
    67       a billion dollars of pain and damage in the last forty years.''
    89   \end{bubble}
    68       \hfill Sir Tony (Hoare)
    90 \end{center}
       
    91 
       
    92 \end{frame}
       
    93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
       
    94 
       
    95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    96 \begin{frame}[c]
       
    97 
       
    98 \mbox{}\\[-25mm]\mbox{}
       
    99 
       
   100 \begin{center}
       
   101   \begin{bubble}[10.5cm]
       
   102   Subject: \textbf{Re: Hate '\textbf{\texttt{val}}'}\hfill 01:02 AM\bigskip\bigskip\\
       
   103 
       
   104   \textcolor{black!70}{
       
   105     \textit{\large<<my usual rant about fp\ldots\\ concurrency bla bla\ldots{} better programs
       
   106     yada>>}}\bigskip\bigskip\bigskip
       
   107   
       
   108   PS: What are you trying to do where you desperately want to use \texttt{var}?
       
   109   \end{bubble}
       
   110 \end{center}
       
   111 
       
   112 \end{frame}
       
   113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
       
   114 
       
   115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   116 \begin{frame}[c,fragile]
       
   117 
       
   118 \begin{textblock}{6}(0.5,0.5)
       
   119 \begin{bubble}[11.5cm]
       
   120   \small  
       
   121   Subject: \textbf{Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:04 AM\medskip\\
       
   122 
       
   123   \textbf{Right now my is\_legal function works fine:}
       
   124   
       
   125 \footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
       
   126  def is_legal(dim: Int, path: Path)(x: Pos): Boolean = {
       
   127    var boolReturn = false
       
   128    if(x._1 > dim || x._2 > dim || x._1 < 0 || x._2 < 0) {
       
   129    else { var breakLoop = false
       
   130           if(path == Nil) { boolReturn = true }
       
   131           else { for(i <- 0 until path.length) {
       
   132                     if(breakLoop == false) {
       
   133                       if(path(i) == x) {
       
   134                         boolReturn = true
       
   135                         breakLoop = true
       
   136                       }
       
   137                       else { boolReturn = false }
       
   138                     } else breakLoop
       
   139             }
       
   140           }
       
   141           boolReturn
       
   142    }
       
   143 \end{lstlisting}
    69 \end{bubble}
   144 \end{bubble}
    70 \end{textblock}
   145 \end{textblock}
    71   
   146 
    72 \begin{textblock}{5}(11.8,1)
   147 \begin{textblock}{6}(8.2,11.8)
    73 \includegraphics[scale=0.20]{hoare.jpg}\\
   148 \begin{bubble}[5.5cm]\footnotesize\bf
    74 \end{textblock}
   149 \ldots{}but I can’t make it work with boolReturn being val. What approach would
    75   
   150 you recommend in this case, and is using var in this case justified?
    76 \end{frame}
   151 \end{bubble}
    77 
   152 \end{textblock}
    78 
   153 
    79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   154 \only<2>{
    80 \begin{frame}[c]
   155 \begin{textblock}{6}(0.3,11.8)
    81 \frametitle{\huge\textbf{\texttt{return}}}
   156   \begin{bubble}[3.1cm]
    82 
   157     \textbf{Me:} \includegraphics[scale=0.08, valign=t]{../pics/throwup.jpg}
    83 \begin{center}\LARGE
   158   \end{bubble}
    84 you should never use it
   159 \end{textblock}}
    85 \end{center}
   160 
    86 
   161 \end{frame}
    87 \end{frame}
   162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
   163 
       
   164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   165 \begin{frame}[t,fragile]
       
   166 
       
   167 \mbox{}\\[-25mm]\mbox{}
       
   168 
       
   169 \begin{textblock}{6}(0.5,2)
       
   170   \begin{bubble}[11.5cm]
       
   171   Subject: \textbf{Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:06 AM\bigskip\\
       
   172   \small
       
   173   
       
   174   OK. So you want to make sure that the \texttt{x}-position is not outside the
       
   175   board....and furthermore you want to make sure that the \texttt{x}-position
       
   176   is not yet in the path list. How about something like\bigskip
       
   177 
       
   178 \footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
       
   179  def is_legal(dim: Int, path: Path)(x: Pos): Boolean = 
       
   180  ...<<some board conditions>>... && !path.contains(x)
       
   181 \end{lstlisting}\bigskip
       
   182   
       
   183   \small Does not even contain a \texttt{val}.
       
   184   \end{bubble}
       
   185 \end{textblock}
       
   186 
       
   187 \begin{textblock}{6}(7,12)
       
   188 \footnotesize\textcolor{black!50}{(This is all on one line)}
       
   189 \end{textblock}
       
   190 
       
   191 \end{frame}
       
   192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
       
   193 
       
   194 
       
   195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   196 \begin{frame}[t,fragile]
       
   197 
       
   198 \mbox{}\\[-15mm]\mbox{}
       
   199 
       
   200 \begin{textblock}{6}(1,3)
       
   201   \begin{bubble}[10.5cm]
       
   202     Subject: \textbf{Re: Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 11:02 AM\bigskip\bigskip\\
       
   203     
       
   204     THANK YOU! You made me change my coding perspective. Because of you,
       
   205     I figured out the next one\ldots
       
   206   \end{bubble}
       
   207 \end{textblock}
       
   208 
       
   209 \end{frame}
       
   210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    89 
   211 
    90 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    91 \begin{frame}[c]
   213 \begin{frame}[c]
    92 \frametitle{Types}
   214 \frametitle{Types}
    93 
   215 
   120 \end{itemize}  
   242 \end{itemize}  
   121 
   243 
   122 \end{frame}
   244 \end{frame}
   123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   124 
   246 
       
   247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
       
   248 
       
   249 \begin{frame}[t]
       
   250 \frametitle{Where to go on from here?}
       
   251 
       
   252 \begin{itemize}
       
   253 \item Martin Odersky (EPFL)\ldots he is currently throwing out everything
       
   254   and starts again with the dotty compiler for Scala\medskip
       
   255 
       
   256 \item Elm (\url{http://elm-lang.org})\ldots web applications with style\medskip   
       
   257 
       
   258 \item Haskell, Ocaml, Standard ML, Scheme 
       
   259 \end{itemize}  
       
   260 \end{frame}
       
   261 
       
   262 
       
   263 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   264 
   125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   126 \begin{frame}[c]
   266 \begin{frame}[c]
   127 \frametitle{\begin{tabular}{c}\\[3cm]\alert{Questions?}\end{tabular}}
   267 \frametitle{\begin{tabular}{c}\\[3cm]\alert{Questions?}\end{tabular}}
   128 
   268 
   129 \mbox{}
   269 \mbox{}\footnotesize
       
   270 Thanks: ``\it{}By the way -  Scala is really getting quite fun
       
   271 when you start to get the hang of it\ldots''
       
   272 
   130 \end{frame}
   273 \end{frame}
   131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   132 \end{document}
   275 \end{document}
   133 
   276 
   134 
   277