17

Copy of scala tech talk

Embed Size (px)

DESCRIPTION

Quick

Citation preview

Page 1: Copy of scala tech talk
Page 2: Copy of scala tech talk

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

Page 3: Copy of scala tech talk

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

1 ~ 2 ~ 3

Page 4: Copy of scala tech talk

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

Page 5: Copy of scala tech talk

Please please PLEASE ...

READ THE STYLE GUIDE

Page 6: Copy of scala tech talk

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

Page 7: Copy of scala tech talk

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

Page 8: Copy of scala tech talk

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)

Page 9: Copy of scala tech talk

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.

Page 10: Copy of scala tech talk

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

Page 11: Copy of scala tech talk

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.

Page 12: Copy of scala tech talk

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)

Page 13: Copy of scala tech talk

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

ints: List[Int] = ?

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

Page 14: Copy of scala tech talk

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

Page 15: Copy of scala tech talk

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

Page 17: Copy of scala tech talk

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