copy of scala tech talk

Post on 07-May-2015

92 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Quick

TRANSCRIPT

Misconceptions - Let’s wipe the slate1. Steep learning curve2. A lot of strange syntax3. Too powerful / expressive

Misconceptions - Let’s wipe the slate1. Steep learning curve2. A lot of strange syntax3. Too powerful / expressive

1 ~ 2 ~ 3

Misconceptions - Let’s wipe the slate1. Steep learning curve2. A lot of strange syntax3. Too powerful / expressive

Use Intellij, Google, Stackoverflow & scala-lang.org

With great power comes great responsibility….

1 ~ 2 ~ 3

Please please PLEASE ...

READ THE STYLE GUIDE

How to write unreadable Scala1. Type inference overuse. Type inference should only be used for local variables & private fields, AND when the type is obvious

e.g.Inferred:val name = "Daniel"

Explicit:

def add(x: Int, y: Int): Int = x + y

How to write unreadable Scala2. Terrible naming. Single character names in long methods (long in scala is 5 - 10 lines). Omitting vowels.

3. Long methods. Try to stick to a single semantic line so you need not use { }. e.g.

def parseArgs[T](args: Args, functions: Map[String, ArgToFilter[T]]): List[T => Boolean] =

functions.filter(pair => args.m.get(pair._1).isDefined).map {

case (option, function) => function(option)

}

.mapValues(System.err.println).keySet.toList

How to write unreadable Scala4. Using ._N instead of pattern matching. E.g. val someMap: Map[Int, (String, SomeClass)] = ?

someMap.map(t => t._1.toString + t._2._2 + t._2._1)

(Also see my early code)

5. ⌘⌥L Ignorance - i.e. not formatting your code as per the style guide. E.g.

(see Szymon)

How to write unreadable Scala6. Overuse of Infix notation over dot notation (show youtube tab)

7. Functional for the sake of functional - Scala is MULTIparadigm. E.g. using recursion when a while loop would be easier to understand.

Genuine Negatives1. No backward compatibility2. Slow compile time3. SBT can be agony

Genuine Negatives in 1 or 2 years1. No backward compatibility Will stabilize2. Slow compile time Moore’s Law - Stuff always gets faster (except Windows)3. SBT can be agony? Let’s hope it improves.

Multiparadigm Programming1. Functions are treated like objects and objects are treated like functions. Control flow is by passing around functions rather than using keywords, state and blocks. E.g.

val filters: List[User => Boolean] = ?

((1 until n).map(_ + ", ") :+ n).foreach(print)

print((1 until n).mkString("", ", ", ", " + n)) //proper

(show GenMapFactory, then InterviewQuestions)

Brevityval filters: List[Int => Boolean] = ?val

ints: List[Int] = ?

ints.filter(i => filters.forall(_(i)))

Positives1. Easily 10th of the code for large applications than common OO languages2. Code Quality. Functional means less bugs, and brevity means less bugs3. Very easy to write multithreaded applications, and naturally supports

parallelization4. Well written Scala is very easy to read, it can read like normal english5. So less time spent unit testing6. Monadic design makes exceptions, errors and edge cases easy to handle7. Monadic design makes things very type safe8. Awesome features: Pattern matching, named & default params, duck

typing, etc

Future and Use CasesUse cases: EVERYTHING!!! (well except very low level)

1. Web - can use Play Framework2. Multithreaded applications - use Actors, Akka3. Big Data - Cascading, Scalding, Scoobi, Scrunch, Spark

4. Science - ScalaLab, Breeze Linear Algebra, MLBase5. Scripting - REPL, and can easily write bash inside Scala and Scala inside bash

Interview Questions and Tricksclone rd-core, checkout with-interview-questions branch, then:

1. cmd + shift + n, type InterviewQuestions, press enter, for some nice interview questions

2. cmd + shift + n, type ScalaTricks, press enter, for some scala tips and tricks

top related