handouts/pep-ho.tex
changeset 343 c8fcc0e0a57f
parent 335 7e00d2b13b04
child 352 97bcf8efe4e0
--- a/handouts/pep-ho.tex	Sat Aug 29 16:05:59 2020 +0100
+++ b/handouts/pep-ho.tex	Tue Oct 13 10:21:21 2020 +0100
@@ -91,6 +91,9 @@
 %% 
 %% Section 10 about strings; interpolations and multiline strings
 
+% Easy installation
+%https://alexarchambault.github.io/posts/2020-09-21-cs-setup.html
+
 
 % Exact colors from NB
 \usepackage[breakable]{tcolorbox}
@@ -1617,6 +1620,67 @@
 %\subsection*{Coursework}
 
 
+\subsection*{Scala Syntax for Java Developers}
+
+Scala compiles to the JVM, like the Java language. Because of this,
+it can re-use many libraries.
+
+\begin{lstlisting}[language=Java]
+Drink coke = getCoke();
+\end{lstlisting}
+
+\begin{lstlisting}[language=Scala]
+val coke : Drink = getCoke()
+\end{lstlisting}
+
+Unit means void:
+
+\begin{lstlisting}[language=Java]
+public void output(String s) {
+  System.out.println(s);
+}
+\end{lstlisting}
+
+\begin{lstlisting}[language=Scala]
+def output(s: String): Unit = println(s)
+\end{lstlisting}
+
+
+Type for list of Strings:
+
+\begin{lstlisting}[language=Java]
+List<String>
+\end{lstlisting}
+
+\begin{lstlisting}[language=Scala]
+List[String]
+\end{lstlisting}
+
+String interpolations
+
+\begin{lstlisting}[language=Java]
+System.out.println("Hello, "+ firstName + " "+ lastName + "!");
+\end{lstlisting}
+
+\begin{lstlisting}[language=Scala]
+println(s"Hello, $firstName $lastName!")
+\end{lstlisting}
+
+
+Java provides syntactic sugar when constructing lambda functions:
+
+\begin{lstlisting}[language=Java]
+list.foreach(item -> System.out.println("* " + item));
+\end{lstlisting}
+
+In Scala, we use the => symbol with anonymous functions:
+
+\begin{lstlisting}[language=Scala]
+list.foreach(item => println(s"* $item"))
+\end{lstlisting}
+
+new / vs case classes
+
 
 \subsection*{More Info}