The document is a presentation on the Scala programming language. It introduces Scala as a scalable, statically typed language that blends object-oriented and functional programming. Some key features highlighted include running on the JVM, first-class functions, immutable data structures, pattern matching, and using an actor model for concurrency. Examples are provided to illustrate concepts like mapping, reducing, currying and actors. The presenter argues that Scala is fast, leverages Java libraries, is highly expressive yet statically typed, and facilitates concurrent programming.
6. What is Scala?
✦ Pronounced ‘skah-lak’
✦ Scalable Language
✦ Tastefully typed language
✦ Blend of object-oriented and functional
programming
Tuesday, May 24, 2011
7. What is Scala?
✦ Uses the glorious JVM
✦ Can be used as scripting language
✦ Compiled!
✦ Everything is an expression!
Tuesday, May 24, 2011
9. Grows on you
✦ Looks like modern dynamically typed
languages (Python, Ruby, etc.)
✦ Unlike Python, maps in scala is not a language
syntax! {‘key’: ‘value’}
Tuesday, May 24, 2011
10. Growing new types
✦ BigInt looks like a built-in type, because you
can use integer literals and operators such as
(*, -, and +) with values of that type
Tuesday, May 24, 2011
11. What makes Scala scalable?
✦ Scala is object oriented in pure form!
✦ Every value is an object and every
operation is a method call
✦ Scala is full-blown functional programming
language
Tuesday, May 24, 2011
12. Functional?
✦ Lisp late 50s
✦ Scheme, SML, Erlang, Haskell, OCaml, and
F#
✦ For long time, popular in academia, but not in
industry
Tuesday, May 24, 2011
13. What’s functional?
✦ Functions return a value, given a set of
parameters a function has one possible result.
Tuesday, May 24, 2011
14. Two Main Ideas: I
Functions are first-class citizens
Tuesday, May 24, 2011
15. Citizens?
✦ A function is a value of the same status as, say,
an integer or a string.
✦ You can pass functions as arguments to other
functions
✦ Return functions as a results from functions
✦ Store them in variables
Tuesday, May 24, 2011
16. Functions, citizens?
✦ You can define functions without giving them
a name, sprinkling your code with function
literals as easy as integer literals, like 25
✦ A good example is the pain in writing code for
event handling in java
Tuesday, May 24, 2011
18. Two Main Ideas: II
✦ Operations of a program should map input
values to output values rather than change
data in place
✦ Consider the difference between Strings in
Java and Ruby!
✦ Immutable data structures are the
cornerstone of functional programming
Tuesday, May 24, 2011
19. Referential
Transparency
Tuesday, May 24, 2011
20. State is the evil!
Pun intended
Tuesday, May 24, 2011
21. Multi-core problems
✦ The future!
✦ Threading is damn hard to get right
✦ Memory overhead
✦ Dead locks?
✦ Shared state? Monitor? Mutex?
Semaphore?
✦ Demand for highly concurrent application is
increasing
Tuesday, May 24, 2011
23. Why Scala?
✦ The Java Virtual Machine
✦ Concise (programs are shorter)
Tuesday, May 24, 2011
24. Why Scala??
✦ A rich static type system that gets out of your
way when you don’t need it, is awesome when
you do. (Type Inference). Verifiable!
✦ Flexible syntax
✦ Immutable and mutable variables
Tuesday, May 24, 2011
25. Why Scala??
✦ Functional programming features: mapping,
filtering, folding, currying, so much more.
✦ FAST! (most of the times as fast as Java)
✦ Can call any Java code
✦ Can be called by any Java code
Tuesday, May 24, 2011
30. Concurrency
✦ Actor model! (kinda like erlang)
✦ Threads
✦ Any other JVM concurrency framework
(Netty, Apache Mina, etc.)
Tuesday, May 24, 2011
31. Concurrency :: Actor
✦ Actor Mode: a different way to implement
concurrency
✦ Each object is an actor
✦ Each actor has a mailbox
✦ Actors (asynchronously) send messages and
receive them in their mailbox
✦ No Shared State
✦ Why?
Tuesday, May 24, 2011
32. Actors :: Performance
✦ Apache (C/Threads) vs. Yaws (Erlang/Actor)
Tuesday, May 24, 2011
33. Actors :: Simpler
✦ Code is design around single-threaded mind
✦ No Mutable State
✦ No (Dead) lock
Tuesday, May 24, 2011