handouts/pep-ho.tex
changeset 441 3bfe81972674
parent 426 b51467741af2
child 442 c86e7dd198bf
equal deleted inserted replaced
440:f3bfc496d6ca 441:3bfe81972674
   122 \definecolor{cellbackground}{HTML}{F7F7F7}
   122 \definecolor{cellbackground}{HTML}{F7F7F7}
   123 
   123 
   124 
   124 
   125     
   125     
   126 \begin{document}
   126 \begin{document}
   127 \fnote{\copyright{} Christian Urban, King's College London, 2017, 2018, 2019, 2020, 2021}
   127 \fnote{\copyright{} Christian Urban, King's College London, 2017, 2018, 2019, 2020, 2021, 2022}
   128 
   128 
   129 %\begin{tcolorbox}[breakable,size=fbox,boxrule=1pt,pad at break*=1mm,colback=cellbackground,colframe=cellborder]
   129 %\begin{tcolorbox}[breakable,size=fbox,boxrule=1pt,pad at break*=1mm,colback=cellbackground,colframe=cellborder]
   130 %  abd
   130 %  abd
   131 %\end{tcolorbox}
   131 %\end{tcolorbox}
   132 
   132 
   168 \end{quote}
   168 \end{quote}
   169 
   169 
   170 \noindent\alert
   170 \noindent\alert
   171 Just make sure you are downloading the ``battle tested'' version of
   171 Just make sure you are downloading the ``battle tested'' version of
   172 Scala \textbf{2.13} This is the one I am going to use in the lectures and
   172 Scala \textbf{2.13} This is the one I am going to use in the lectures and
   173 in the coursework. The newer Scala 3.0 \& 3.1 still have some
   173 in the coursework. The newer Scala 3.1 \& 3.2 still have some
   174 features not fully implemented.\bigskip
   174 features not fully implemented.\bigskip
   175 
   175 
   176 \noindent
   176 \noindent
   177 If you are interested, there are also experimental backends of Scala
   177 If you are interested, there are also experimental backends of Scala
   178 for producing code under Android (\url{http://scala-android.org}); for
   178 for producing code under Android (\url{http://scala-android.org}); for
   219   evaluate small code snippets in the Scala REPL. I use the internal
   219   evaluate small code snippets in the Scala REPL. I use the internal
   220   terminal to run Scala 2.13.6.\label{vscode}}
   220   terminal to run Scala 2.13.6.\label{vscode}}
   221 \end{boxedminipage}
   221 \end{boxedminipage}
   222 \end{figure}  
   222 \end{figure}  
   223 
   223 
   224 What I like most about VS Code is that it provides easy access to the
   224  Actually \alert last year I switched to VS Codium, which is VS Code minus
       
   225 all the telemetry that is normally sent to Microsoft. Apart from the
       
   226  telemetry,  it works pretty much the same as the original but is driven
       
   227 by a dedicated community, rather than a big company. You can download
       
   228 VS Codium from
       
   229 
       
   230 \begin{quote}
       
   231 \url{https://vscodium.com}
       
   232 \end{quote}
       
   233 
       
   234 
       
   235 What I like most about VS Code/Codium is that it provides easy access to the
   225 Scala REPL. But if you prefer another editor for coding, it is also
   236 Scala REPL. But if you prefer another editor for coding, it is also
   226 painless to work with Scala completely on the command line (as you might
   237 painless to work with Scala completely on the command line (as you might
   227 have done with \texttt{g++} in the earlier part of PEP). For the
   238 have done with \texttt{g++} in the earlier part of PEP). For the
   228 lazybones among us, there are even online editors and environments for
   239 lazybones among us, there are even online editors and environments for
   229 developing and running Scala programs: \textit{ScalaFiddle}
   240 developing and running Scala programs: \textit{ScalaFiddle}
   237   
   248   
   238 \noindent
   249 \noindent
   239 But you should be careful if you use them for your coursework: they
   250 But you should be careful if you use them for your coursework: they
   240 are meant to play around, not really for serious work. 
   251 are meant to play around, not really for serious work. 
   241 
   252 
   242 As one might expect, Scala can be used with the heavy-duty IDEs Eclipse and IntelliJ.
   253 As one might expect, Scala can be used with the heavy-duty IDEs
   243 A ready-made Scala bundle for Eclipse is available from
   254 Eclipse and IntelliJ.  A ready-made Scala bundle for Eclipse is
       
   255 available from
   244 
   256 
   245 \begin{quote}
   257 \begin{quote}
   246 \url{http://scala-ide.org/download/sdk.html}
   258 \url{http://scala-ide.org/download/sdk.html}
   247 \end{quote}
   259 \end{quote}
   248 
   260 
   445 laziness, implicits, algebraic datatypes  to name a few. Imperative
   457 laziness, implicits, algebraic datatypes  to name a few. Imperative
   446 languages seem to often lag behind in adopting them: I know, for
   458 languages seem to often lag behind in adopting them: I know, for
   447 example, that Java will at some point in the future support
   459 example, that Java will at some point in the future support
   448 pattern-matching, which has been used for example in SML for at least
   460 pattern-matching, which has been used for example in SML for at least
   449 40(!) years. See
   461 40(!) years. See
   450 \url{http://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html}.
   462 \url{https://openjdk.org/projects/amber/design-notes/patterns/pattern-matching-for-java}.
   451 Automatic garbage collection was included in Java in 1995; the
   463 Automatic garbage collection was included in Java in 1995; the
   452 functional language LISP had this already in 1958. Generics were added
   464 functional language LISP had this already in 1958. Generics were added
   453 to Java 5 in 2004; the functional language SML had it since 1990.
   465 to Java 5 in 2004; the functional language SML had it since 1990.
   454 Higher-order functions were added to C\# in 2007, to Java 8 in
   466 Higher-order functions were added to C\# in 2007, to Java 8 in
   455 2014; again LISP had them since 1958. Also Rust, a C-like programming
   467 2014; again LISP had them since 1958. Also Rust, a C-like programming
   456 language that has been developed since 2010 and is gaining quite some
   468 language that has been developed since 2010 and is gaining quite some
   457 interest, borrows many ideas from functional programming from
   469 interest, borrows many ideas from functional programming from
   458 yesteryear.}\medskip
   470 yesteryear.}\medskip
   459 
   471 
   460 \noindent
   472 \noindent
   461 If you need any after-work distractions, you might have fun reading this
   473 If you need any after-work distractions, you might have fun reading
   462 about FP (functional programming):
   474 this about FP (functional programming) --- you
       
   475 might have to disable your browser cookies though if you want to read
       
   476 it for free. And spoiler alert: This is tongue-in-cheek \texttt{;o)}
   463 
   477 
   464 \begin{quote}
   478 \begin{quote}
   465 \url{https://medium.com/better-programming/fp-toy-7f52ea0a947e}
   479 \url{https://betterprogramming.pub/fp-toy-7f52ea0a947e}
   466 \end{quote}
   480 \end{quote}
   467 
   481 
   468 \subsection*{The Very Basics}
   482 \subsection*{The Very Basics}
   469 
   483 
   470 One advantage of Scala over Java is that it includes an interpreter (a
   484 One advantage of Scala over Java is that it includes an interpreter (a
   476 programs. Once you installed Scala, you can start the interpreter by
   490 programs. Once you installed Scala, you can start the interpreter by
   477 typing on the command line:
   491 typing on the command line:
   478 
   492 
   479 \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
   493 \begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
   480 $ scala
   494 $ scala
   481 Welcome to Scala 2.13.6 (OpenJDK 64-Bit Server VM, Java 17).
   495 Welcome to Scala 2.13.9 (OpenJDK 64-Bit Server VM, Java 17.0.1).
   482 Type in expressions for evaluation. Or try :help.
   496 Type in expressions for evaluation. Or try :help.
   483 
   497 
   484 scala>
   498 scala>
   485 \end{lstlisting}%$
   499 \end{lstlisting}%$
   486 
   500 
  1713 list.foreach(item -> System.out.println("* " + item));
  1727 list.foreach(item -> System.out.println("* " + item));
  1714 /*!\annotation{Java}!*/
  1728 /*!\annotation{Java}!*/
  1715 \end{lstlisting}
  1729 \end{lstlisting}
  1716 
  1730 
  1717 \noindent
  1731 \noindent
  1718 In Scala, we use the \code{=>} symbol:
  1732 In Scala, we use the \code{=>} symbol for the same:
  1719 
  1733 
  1720 \begin{lstlisting}[language=Scala]
  1734 \begin{lstlisting}[language=Scala]
  1721 list.foreach(item => println(s"* $item"))/*!\annotation{Scala}!*/
  1735 list.foreach(item => println(s"* $item"))/*!\annotation{Scala}!*/
  1722 \end{lstlisting}%$
  1736 \end{lstlisting}%$
  1723 \end{boxedminipage}
  1737 \end{boxedminipage}
  1782 production code, but then moved away from it. Allegedly they did not
  1796 production code, but then moved away from it. Allegedly they did not
  1783 like the steep learning curve of Scala and also that new versions of
  1797 like the steep learning curve of Scala and also that new versions of
  1784 Scala often introduced incompatibilities in old code. Also the Java
  1798 Scala often introduced incompatibilities in old code. Also the Java
  1785 language is lately developing at lightening speed (in comparison to the past) 
  1799 language is lately developing at lightening speed (in comparison to the past) 
  1786 taking on many
  1800 taking on many
  1787 features of Scala and other languages, and it seems even it introduces
  1801 features of Scala and other languages, and it seems it even introduces
  1788 new features on its own.
  1802 new features on its own.
  1789 
  1803 
  1790 
  1804 
  1791 Scala is deep: After many years, I still continue to learn new technique
  1805 Scala is deep: After many years, I still continue to learn new technique
  1792 for writing more elegant code.
  1806 for writing more elegant code. Unfortunately, I have not yet managed to
       
  1807 switch over my code to Scala 3.0 due to time constraints. Scala 3 seems
       
  1808 to iron out a number of snags from Scala 2, but why on earth are they
       
  1809 introducing Python-esque intendation and why on earth are they
       
  1810 re-introducing the \texttt{then}-keyword in Scala 3, when I just about got
       
  1811 comfortable without it? 
  1793 
  1812 
  1794 %So all in all, Scala might not be a great teaching language,
  1813 %So all in all, Scala might not be a great teaching language,
  1795 %but I hope this is mitigated by the fact that I never require
  1814 %but I hope this is mitigated by the fact that I never require
  1796 %you to write any Scala code. You only need to be able to read
  1815 %you to write any Scala code. You only need to be able to read
  1797 %it. In the coursework you can use any programming language you
  1816 %it. In the coursework you can use any programming language you