annotate 4-Scala/README.txt @ 70:4198fa4e0df4

Add Scala code and notes
author IBBoard <dev@ibboard.co.uk>
date Sat, 14 Oct 2017 13:39:41 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 I've already done Scala development at work, so most of this is just a recap.
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 A few things I learned:
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 * Never used traits before - mini classes defined with "trait" keyword and included
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 like a "mixin" with the "with" keyword to 'inherit' functionality from multiple parents
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 * Nil is an empty list - probably useful when iterating things and returning a Nil
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 * foldLeft either uses strange syntax ("start /: list {(a, b) … }") or uses currying
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 ("list.foldLeft(start)((a,b) …)")
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 * Strings can be converted to regexes by adding ".r" at the end (I think my work code
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 managed to do without string matching)
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 * Pattern matching with a "match… case" on XML can use squiggly brackets to name a variable
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 (e.g. "case <movie>{movieName}</movie>" matches the tag and puts the contents in movieName)
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 * Scala has a few minor problems:
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 * 2.12 (RPM from the website) won't run files as "scala filename.scala" - it needs to be
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 "scala -nc filename.scala" to disable the compilation daemon
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 * "scala -e <code>" doesn't seem to want to work without "-nc" either
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 * If there are dependencies then it is easier to use sbt. Download from
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 http://www.scala-sbt.org/download.html, create a standard "project/src/scala/package"
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 structure then create build.sbt within "project/" with the contents:
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 name := "Project-Name"
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 version := "1.0"
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 scalaVersion := "2.12.3"
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 Run the project by cd-ing into the project directory and running "sbt run"
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 * Actors have been deprecated and replaced by Akka
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 * sbt compiles code, so you can't have code outside a class or object
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 * Akka actors can only act - they can't easily have other methods as well because
4198fa4e0df4 Add Scala code and notes
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 creation returns a generic Akka reference to the actor, which doesn't expose the method