view 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
line wrap: on
line source

I've already done Scala development at work, so most of this is just a recap.

A few things I learned:

 * Never used traits before - mini classes defined with "trait" keyword and included
   like a "mixin" with the "with" keyword to 'inherit' functionality from multiple parents
 * Nil is an empty list - probably useful when iterating things and returning a Nil
 * foldLeft either uses strange syntax ("start /: list {(a, b) … }") or uses currying
   ("list.foldLeft(start)((a,b) …)")
 * Strings can be converted to regexes by adding ".r" at the end (I think my work code
   managed to do without string matching)
 * Pattern matching with a "match… case" on XML can use squiggly brackets to name a variable
  (e.g. "case <movie>{movieName}</movie>" matches the tag and puts the contents in movieName)
 * Scala has a few minor problems:
   * 2.12 (RPM from the website) won't run files as "scala filename.scala" - it needs to be
     "scala -nc filename.scala" to disable the compilation daemon
   * "scala -e <code>" doesn't seem to want to work without "-nc" either
 * If there are dependencies then it is easier to use sbt. Download from
   http://www.scala-sbt.org/download.html, create a standard "project/src/scala/package"
   structure then create build.sbt within "project/" with the contents:
      name := "Project-Name"
      version := "1.0"
      scalaVersion := "2.12.3"
   Run the project by cd-ing into the project directory and running "sbt run"
 * Actors have been deprecated and replaced by Akka
 * sbt compiles code, so you can't have code outside a class or object
 * Akka actors can only act - they can't easily have other methods as well because
   creation returns a generic Akka reference to the actor, which doesn't expose the method