slides/slides02.tex
changeset 317 607ceabeeffc
parent 316 8b57dd326a91
child 318 029e2862bb4e
equal deleted inserted replaced
316:8b57dd326a91 317:607ceabeeffc
   105   \large
   105   \large
   106   \quad{}\;where \;$d_1^2$\; means \;$d_1 \cdot d_1$\; and so on
   106   \quad{}\;where \;$d_1^2$\; means \;$d_1 \cdot d_1$\; and so on
   107 \end{frame}
   107 \end{frame}
   108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   109   
   109   
   110 
   110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
       
   111 \begin{frame}[c]
       
   112   \frametitle{Discussion Forum}
       
   113   
       
   114   \large
       
   115   ``Since we cant use \code{var}s I was wondering if we could use a stack?''
       
   116   \bigskip\bigskip\bigskip\bigskip
       
   117 
       
   118   \small
       
   119   My \pcode{collatz} and \pcode{collatz_max} functions are 4 loc each. 
       
   120 \end{frame}
       
   121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   122 
       
   123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   124 \begin{frame}[t]
       
   125   \frametitle{Email: Hate 'val'}
       
   126   
       
   127   \mbox{}\\[-22mm]\mbox{}
       
   128   
       
   129   \begin{center}
       
   130     \begin{bubble}[10.5cm]
       
   131     Subject: \textbf{Hate '\textbf{\texttt{val}}'}\hfill 01:00 AM\medskip\\
       
   132   
       
   133     Hello Mr Urban,\medskip\\
       
   134   
       
   135     I just wanted to ask, how are we suppose to work
       
   136     with the completely useless \textbf{\texttt{val}}, that can’t be changed ever? Why is
       
   137     this rule active at all? I’ve spent 4 hours not thinking on the
       
   138     coursework, but how to bypass this annoying rule. What’s the whole
       
   139     point of all these coursework, when we can’t use everything Scala
       
   140     gives us?!?\medskip\\
       
   141   
       
   142     Regards.\\
       
   143     \mbox{}\hspace{5mm}\textcolor{black!50}{<<deleted>>}\\
       
   144     \end{bubble}
       
   145   \end{center}
       
   146   
       
   147 \end{frame}
       
   148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
       
   149   
       
   150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   151 \begin{frame}[c]
       
   152 
       
   153  \mbox{}\\[-25mm]\mbox{}
       
   154 
       
   155 \begin{center}
       
   156   \begin{bubble}[10.5cm]
       
   157   Subject: \textbf{Re: Hate '\textbf{\texttt{val}}'}\hfill 01:02 AM\bigskip\bigskip\\
       
   158 
       
   159   \textcolor{black!70}{
       
   160     \textit{\large<<my usual rant about fp\ldots\\ concurrency bla bla\ldots{} better programs
       
   161     yada>>}}\bigskip\bigskip\bigskip
       
   162   
       
   163   PS: What are you trying to do where you desperately want to use \texttt{var}?
       
   164   \end{bubble}
       
   165 \end{center}
       
   166 
       
   167 \end{frame}
       
   168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
       
   169 
       
   170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   171 \begin{frame}[c,fragile]
       
   172 
       
   173 \begin{textblock}{6}(0.5,0.5)
       
   174 \begin{bubble}[11.5cm]
       
   175   \small  
       
   176   Subject: \textbf{Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:04 AM\medskip\\
       
   177 
       
   178   \textbf{Right now my is\_legal function works fine:}
       
   179   
       
   180 \footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
       
   181  def is_legal(dim: Int, path: Path)(x: Pos): Boolean = {
       
   182    var boolReturn = false
       
   183    if(x._1 > dim || x._2 > dim || x._1 < 0 || x._2 < 0) {
       
   184    else { var breakLoop = false
       
   185           if(path == Nil) { boolReturn = true }
       
   186           else { for(i <- 0 until path.length) {
       
   187                     if(breakLoop == false) {
       
   188                       if(path(i) == x) {
       
   189                         boolReturn = true
       
   190                         breakLoop = true
       
   191                       }
       
   192                       else { boolReturn = false }
       
   193                     } else breakLoop
       
   194             }
       
   195           }
       
   196           boolReturn
       
   197    }
       
   198 \end{lstlisting}
       
   199 \end{bubble}
       
   200 \end{textblock}
       
   201 
       
   202 \begin{textblock}{6}(8.2,11.8)
       
   203 \begin{bubble}[5.5cm]\footnotesize\bf
       
   204 \ldots{}but I can’t make it work with boolReturn being val. What approach would
       
   205 you recommend in this case, and is using var in this case justified?
       
   206 \end{bubble}
       
   207 \end{textblock}
       
   208 
       
   209 \only<2>{
       
   210 \begin{textblock}{6}(0.3,11.8)
       
   211   \begin{bubble}[3.1cm]
       
   212     \textbf{Me:}
       
   213     \raisebox{-12mm}{\includegraphics[scale=0.08]{../pics/throwup.jpg}}
       
   214   \end{bubble}
       
   215 \end{textblock}}
       
   216 
       
   217 \end{frame}
       
   218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
       
   219 
       
   220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   221 \begin{frame}[t,fragile]
       
   222 
       
   223 \mbox{}\\[-25mm]\mbox{}
       
   224 
       
   225 \begin{textblock}{6}(0.5,2)
       
   226   \begin{bubble}[11.5cm]
       
   227   Subject: \textbf{Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 01:06 AM\bigskip\\
       
   228   \small
       
   229   
       
   230   OK. So you want to make sure that the \texttt{x}-position is not outside the
       
   231   board....and furthermore you want to make sure that the \texttt{x}-position
       
   232   is not yet in the path list. How about something like\bigskip
       
   233 
       
   234 \footnotesize\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
       
   235  def is_legal(dim: Int, path: Path)(x: Pos): Boolean = 
       
   236    ...<<some board conditions>>... && !path.contains(x)
       
   237 \end{lstlisting}\bigskip
       
   238   
       
   239   \small Does not even contain a \texttt{val}.
       
   240   \end{bubble}
       
   241 \end{textblock}
       
   242 
       
   243 \begin{textblock}{6}(7,12)
       
   244 \footnotesize\textcolor{black!50}{(This is all on one line)}
       
   245 \end{textblock}
       
   246 
       
   247 \end{frame}
       
   248 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
       
   249 
       
   250 
       
   251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   252 \begin{frame}[t,fragile]
       
   253 
       
   254 \mbox{}\\[-15mm]\mbox{}
       
   255 
       
   256 \begin{textblock}{6}(1,3)
       
   257   \begin{bubble}[10.5cm]
       
   258     Subject: \textbf{Re: Re: Re: Re: Hate '\textbf{\texttt{val}}'}\hfill 11:02 AM\bigskip\bigskip\\
       
   259     
       
   260     THANK YOU! You made me change my coding perspective. Because of you,
       
   261     I figured out the next one\ldots
       
   262   \end{bubble}
       
   263 \end{textblock}
       
   264 
       
   265 \only<2>{
       
   266 \begin{textblock}{6}(0.3,11.8)
       
   267   \begin{bubble}[3.1cm]
       
   268     \textbf{Me:}
       
   269     \raisebox{-12mm}{\includegraphics[scale=0.15]{../pics/happy.jpg}}
       
   270   \end{bubble}
       
   271 \end{textblock}}
       
   272 
       
   273 \end{frame}
       
   274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
       
   275 
       
   276 
       
   277  
   111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
   278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
   112 \begin{frame}[c]
   279 \begin{frame}[c]
   113 \frametitle{Assignments}
   280 \frametitle{Assignments}
   114 
   281 
   115 Don't change anything with the templates!\bigskip
   282 Don't change any names or types in the templates!\bigskip
   116 
   283 
   117 Avoid at all costs:
   284 Avoid at all costs:
   118 
   285 
   119 \begin{itemize}
   286 \begin{itemize}
   120 \item \texttt{var} 
   287 \item \code{var} 
   121 \item \texttt{return} 
   288 \item \code{return} 
   122 \item \texttt{ListBuffer}
   289 \item \texttt{ListBuffer}
   123 \item \texttt{mutable}
   290 \item \texttt{mutable}
   124 \item \texttt{.par}  
   291 \item \texttt{.par}  
   125 \end{itemize}\pause\bigskip
   292 \end{itemize}\bigskip\bigskip
   126 
   293 
   127 
   294 I cannot think of a good reason to use stacks.
   128 \mbox{}\hfill\textit{``Scala --- \underline{S}lowly \underline{c}ompiled 
       
   129 \underline{a}cademic \underline{la}nguage''}\smallskip\\
       
   130 \mbox{}\hfill\textit{ --- a joke(?) found on Twitter}\bigskip
       
   131 \end{frame}
       
   132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   133 
       
   134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   135 \begin{frame}[t]
       
   136 \frametitle{Email: Hate 'val'}
       
   137 
       
   138 \mbox{}\\[-25mm]\mbox{}
       
   139 
       
   140 \begin{center}
       
   141   \begin{bubble}[10.5cm]
       
   142   Subject: \textbf{Hate '\textbf{\texttt{val}}'}\hfill 01:00 AM\medskip\\
       
   143 
       
   144   Hello Mr Urban,\medskip\\
       
   145 
       
   146   I just wanted to ask, how are we suppose to work
       
   147   with the completely useless \textbf{\texttt{val}}, that can’t be changed ever? Why is
       
   148   this rule active at all? I’ve spent 4 hours not thinking on the
       
   149   coursework, but how to bypass this annoying rule. What’s the whole
       
   150   point of all these coursework, when we can’t use everything Scala
       
   151   gives us?!?\medskip\\
       
   152 
       
   153   Regards.\\
       
   154   \mbox{}\hspace{5mm}\textcolor{black!50}{<<deleted>>}\\
       
   155   \end{bubble}
       
   156 \end{center}
       
   157 
       
   158 \end{frame}
       
   159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
       
   160 
       
   161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   162 \def\firstcircle{(0,0) circle (1.4cm)}
       
   163 \def\secondcircle{(0:2cm) circle (1.4cm)}
       
   164 \colorlet{circle edge}{blue!50}
       
   165 \colorlet{circle area}{blue!20}
       
   166 
       
   167 \tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
       
   168     outline/.style={draw=circle edge, thick}}
       
   169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   170 \begin{frame}[c,fragile]
       
   171 \frametitle{Par: Intersections}
       
   172 
       
   173 \begin{textblock}{6}(1,2)
       
   174 \begin{tikzpicture}
       
   175   \draw[outline] \firstcircle node {$A$};
       
   176   \node[anchor=south] at (current bounding box.north)
       
   177     {$A = \{1,2,3,\ldots,1000\}$};
       
   178 \end{tikzpicture}
       
   179 \end{textblock}
       
   180 
       
   181 \begin{textblock}{6}(8,2)
       
   182 \begin{tikzpicture}
       
   183   \draw[outline] \secondcircle node {$B$};
       
   184   \node[anchor=south] at (current bounding box.north)
       
   185     {$B = \{1,5,9,13,\ldots,997\}$};
       
   186 \end{tikzpicture}
       
   187 \end{textblock}
       
   188 
       
   189 \begin{textblock}{6}(3.3,9)
       
   190 \begin{tikzpicture}
       
   191     \begin{scope}
       
   192         \clip \firstcircle;
       
   193         \fill[filled] \secondcircle;
       
   194     \end{scope}
       
   195     \draw[outline] \firstcircle node {$A$};
       
   196     \draw[outline] \secondcircle node {$B$};
       
   197     \node[anchor=north] at (current bounding box.south)
       
   198     {How many elements are in $A \cap B$?};
       
   199 \end{tikzpicture}
       
   200 \end{textblock}  
       
   201 
       
   202 \end{frame}
   295 \end{frame}
   203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   204 
   297 
   205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
   298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
   206 \begin{frame}[t]
   299 \begin{frame}[t]
   283 
   376 
   284 
   377 
   285 
   378 
   286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
   379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
   287 \begin{frame}[t]
   380 \begin{frame}[t]
   288 \frametitle{Why Scala? No null!}
   381 \frametitle{Option Type}
   289 
   382 
   290 
   383 
   291 \begin{itemize}
   384   
   292 \item \large {\bf You can avoid \textcolor{blue}{\texttt{null}}}:
   385 \end{frame}
   293 \end{itemize}
   386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   294 
   387 
   295 
   388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
   296 \begin{textblock}{6}(1,5)
   389 \begin{frame}[t]
   297   \begin{bubble}[10.5cm]\small
   390 \frametitle{Higher-Order Functions}
   298       ``I call it my billion-dollar mistake. It was the invention of
   391   
   299       the null reference in 1965. At that time, I was designing the
   392   
   300       first comprehensive type system for references in an object
   393     
   301       oriented language (ALGOL W). My goal was to ensure that all use
   394 \end{frame}
   302       of references should be absolutely safe, with checking performed
   395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   303       automatically by the compiler. But I couldn't resist the
   396   
   304       temptation to put in a null reference, simply because it was so
       
   305       easy to implement. This has led to innumerable errors,
       
   306       vulnerabilities, and system crashes, which have probably caused
       
   307       a billion dollars of pain and damage in the last forty years.''
       
   308       \hfill Sir Tony (Hoare)
       
   309 \end{bubble}
       
   310 \end{textblock}
       
   311   
       
   312 \begin{textblock}{5}(12.5,1.9)
       
   313 \includegraphics[scale=0.05]{../pics/hoare.jpg}\\
       
   314 \end{textblock}
       
   315   
       
   316 \end{frame}
       
   317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   318 
   397 
   319 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   320 \begin{frame}[c]
   399 \begin{frame}[c]
   321 \frametitle{\begin{tabular}{c}\\[0cm]\alert{Questions?}\end{tabular}}
   400 \frametitle{\begin{tabular}{c}\\[0cm]\alert{Questions?}\end{tabular}}
   322 
   401