Software Engineering Thailand: Programming with Scala

132
Programming with Scala Brian Topping Mauswerks LLC

Transcript of Software Engineering Thailand: Programming with Scala

Page 1: Software Engineering Thailand: Programming with Scala

Programming with ScalaBrian Topping

Mauswerks LLC

Page 2: Software Engineering Thailand: Programming with Scala

About Me• Globally experienced dev with over 25 years professional experience

• Have led teams of three to fifteen developers as lead developer, architect, general manager. Start projects first, then hire when ten fingers are not enough.

• Have been using Scala since 2012, JDK Open Source since 2001

• Interests: Functional Reactive Programming, financial markets, machine learning, Javascript, travel, motorcycles

• Shameless plug: Available for investment or work in BKK

• http://github.com/briantoppinghttp://twitter.com/briantoppinghttp://linkedin.com/in/briantopping

Page 3: Software Engineering Thailand: Programming with Scala

Why Scala?

Page 4: Software Engineering Thailand: Programming with Scala

What is wrong with this picture?

Page 5: Software Engineering Thailand: Programming with Scala

• "Looks good to me, ship it!"

Page 6: Software Engineering Thailand: Programming with Scala

• "Looks good to me, ship it!"

• We're at the wrong level of zoom to see problems

Page 7: Software Engineering Thailand: Programming with Scala

• "Looks good to me, ship it!"

• We're at the wrong level of zoom to see problems

Page 8: Software Engineering Thailand: Programming with Scala

• "Looks good to me, ship it!"

• We're at the wrong level of zoom to see problems

• Solutions at a global level must factor problems at the local level.

Page 9: Software Engineering Thailand: Programming with Scala

• "Looks good to me, ship it!"

• We're at the wrong level of zoom to see problems

• Solutions at a global level must factor problems at the local level.

• Complexity is the natural tradeoff

Page 10: Software Engineering Thailand: Programming with Scala

What is Scala?

• Object Oriented / Functional hybrid

• Compiled to JVM bytecode

• Statically typed (compile time)

• Strongly typed (types must match)

• Growing ecosystem

• Language is stable and mature

Page 11: Software Engineering Thailand: Programming with Scala

(a few) Benefits of Scala

• Seamless Java / JDK ecosystem interoperability

• Type Inferencing & Parameterization

• Concurrency & Distribution

• Collections Classes

• Pattern Matching

• Obvious Correctness

Page 12: Software Engineering Thailand: Programming with Scala

Standard Example

Page 13: Software Engineering Thailand: Programming with Scala

Standard Example

• Java "Bean"

Page 14: Software Engineering Thailand: Programming with Scala

Standard Example

• Java "Bean"

Page 15: Software Engineering Thailand: Programming with Scala

Standard Example

• Java "Bean"

• Scala Case Class

Page 16: Software Engineering Thailand: Programming with Scala

Standard Example

• Java "Bean"

• Scala Case Class

Page 17: Software Engineering Thailand: Programming with Scala

Standard Example

• Java "Bean"

• Scala Case Class

Page 18: Software Engineering Thailand: Programming with Scala

Java / JDK Interoperability

Page 19: Software Engineering Thailand: Programming with Scala

Java / JDK Interoperability

• Scala classes are JVM classes

Page 20: Software Engineering Thailand: Programming with Scala

Java / JDK Interoperability

• Scala classes are JVM classes

• Groovy, Clojure, JRuby, Jython – 40+ in all!

Page 21: Software Engineering Thailand: Programming with Scala

Java / JDK Interoperability

• Scala classes are JVM classes

• Groovy, Clojure, JRuby, Jython – 40+ in all!

• Scala is a mixed Object + Functional language

Page 22: Software Engineering Thailand: Programming with Scala

Java / JDK Interoperability

• Scala classes are JVM classes

• Groovy, Clojure, JRuby, Jython – 40+ in all!

• Scala is a mixed Object + Functional language

• It is possible and common for young teams to start writing Scala with Java style (OOD) and API, test with existing tools

Page 23: Software Engineering Thailand: Programming with Scala

Java / JDK Interoperability

• Scala classes are JVM classes

• Groovy, Clojure, JRuby, Jython – 40+ in all!

• Scala is a mixed Object + Functional language

• It is possible and common for young teams to start writing Scala with Java style (OOD) and API, test with existing tools

• Take advantage of Java libraries

Page 24: Software Engineering Thailand: Programming with Scala

Java / JDK Interoperability

• Scala classes are JVM classes

• Groovy, Clojure, JRuby, Jython – 40+ in all!

• Scala is a mixed Object + Functional language

• It is possible and common for young teams to start writing Scala with Java style (OOD) and API, test with existing tools

• Take advantage of Java libraries

Page 25: Software Engineering Thailand: Programming with Scala

Type Inference & Immutability Focus

Page 26: Software Engineering Thailand: Programming with Scala

Type Inference & Immutability Focus

• Compiler knows the type of an assignment, yet most languages require the developer to prove it

Page 27: Software Engineering Thailand: Programming with Scala

Type Inference & Immutability Focus

• Compiler knows the type of an assignment, yet most languages require the developer to prove it

• Java:

Page 28: Software Engineering Thailand: Programming with Scala

Type Inference & Immutability Focus

• Compiler knows the type of an assignment, yet most languages require the developer to prove it

• Java:

• Scala:

Page 29: Software Engineering Thailand: Programming with Scala

Type Inference & Immutability Focus

• Compiler knows the type of an assignment, yet most languages require the developer to prove it

• Java:

• Scala:

• Built for immutability!

Page 30: Software Engineering Thailand: Programming with Scala

Type Inference & Immutability Focus

• Compiler knows the type of an assignment, yet most languages require the developer to prove it

• Java:

• Scala:

• Built for immutability!

• Use the var keyword for mutable variables

Page 31: Software Engineering Thailand: Programming with Scala

Type Inference & Immutability Focus

• Compiler knows the type of an assignment, yet most languages require the developer to prove it

• Java:

• Scala:

• Built for immutability!

• Use the var keyword for mutable variables

• One finds themselves using it less and less often!

Page 32: Software Engineering Thailand: Programming with Scala

Type Parameterization

Page 33: Software Engineering Thailand: Programming with Scala

Type Parameterization• Types allow you to denote function domain & codomains. For example, from

mathematics, we are used to seeing:this tells us that function “f” maps values from the set of real numbers to values of the set of natural numbers

Page 34: Software Engineering Thailand: Programming with Scala

Type Parameterization• Types allow you to denote function domain & codomains. For example, from

mathematics, we are used to seeing:this tells us that function “f” maps values from the set of real numbers to values of the set of natural numbers

• In the abstract, this is exactly what concrete types are. Type systems give us some more powerful ways to express these sets

Page 35: Software Engineering Thailand: Programming with Scala

Type Parameterization• Types allow you to denote function domain & codomains. For example, from

mathematics, we are used to seeing:this tells us that function “f” maps values from the set of real numbers to values of the set of natural numbers

• In the abstract, this is exactly what concrete types are. Type systems give us some more powerful ways to express these sets

• Given these annotations, the compiler can now statically (at compile time) verify that the program is sound

Page 36: Software Engineering Thailand: Programming with Scala

Type Parameterization• Types allow you to denote function domain & codomains. For example, from

mathematics, we are used to seeing:this tells us that function “f” maps values from the set of real numbers to values of the set of natural numbers

• In the abstract, this is exactly what concrete types are. Type systems give us some more powerful ways to express these sets

• Given these annotations, the compiler can now statically (at compile time) verify that the program is sound

• Variance annotations allow you to express relationships between class hierarchies & polymorphic types

Page 37: Software Engineering Thailand: Programming with Scala

Type Parameterization• Types allow you to denote function domain & codomains. For example, from

mathematics, we are used to seeing:this tells us that function “f” maps values from the set of real numbers to values of the set of natural numbers

• In the abstract, this is exactly what concrete types are. Type systems give us some more powerful ways to express these sets

• Given these annotations, the compiler can now statically (at compile time) verify that the program is sound

• Variance annotations allow you to express relationships between class hierarchies & polymorphic types

• Reference: http://twitter.github.io/scala_school/type-basics.html

Page 38: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution

Page 39: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution• Futures and Promises – Long history across platforms

Page 40: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution• Futures and Promises – Long history across platforms

• Factory objects look like integral part of language

Page 41: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution• Futures and Promises – Long history across platforms

• Factory objects look like integral part of language

• Remember that functions are parameters!

Page 42: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution• Futures and Promises – Long history across platforms

• Factory objects look like integral part of language

• Remember that functions are parameters!

Page 43: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution• Futures and Promises – Long history across platforms

• Factory objects look like integral part of language

• Remember that functions are parameters!

• Don't return values, return a Future!

Page 44: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution• Futures and Promises – Long history across platforms

• Factory objects look like integral part of language

• Remember that functions are parameters!

• Don't return values, return a Future!

• Akka-HTTP is a perfect example, you can return a value, but then your code manages the concurrency. Return a Future to the caller and let it manage it instead!

Page 45: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution• Futures and Promises – Long history across platforms

• Factory objects look like integral part of language

• Remember that functions are parameters!

• Don't return values, return a Future!

• Akka-HTTP is a perfect example, you can return a value, but then your code manages the concurrency. Return a Future to the caller and let it manage it instead!

• Unlike Node, full access to all cores.

Page 46: Software Engineering Thailand: Programming with Scala

Collections Classes

Page 47: Software Engineering Thailand: Programming with Scala

Collections Classes• Scala Collections are what brought me to the language

Page 48: Software Engineering Thailand: Programming with Scala

Collections Classes• Scala Collections are what brought me to the language

• Designed to consistently behave as a collections DSL

Page 49: Software Engineering Thailand: Programming with Scala

Collections Classes• Scala Collections are what brought me to the language

• Designed to consistently behave as a collections DSL

• Immutable by default, great for parallel deployments

Page 50: Software Engineering Thailand: Programming with Scala

Collections Classes• Scala Collections are what brought me to the language

• Designed to consistently behave as a collections DSL

• Immutable by default, great for parallel deployments

• Java

Page 51: Software Engineering Thailand: Programming with Scala

Collections Classes• Scala Collections are what brought me to the language

• Designed to consistently behave as a collections DSL

• Immutable by default, great for parallel deployments

• Java

Page 52: Software Engineering Thailand: Programming with Scala

Collections Classes• Scala Collections are what brought me to the language

• Designed to consistently behave as a collections DSL

• Immutable by default, great for parallel deployments

• Java

• Scala

Page 53: Software Engineering Thailand: Programming with Scala

Collections Classes• Scala Collections are what brought me to the language

• Designed to consistently behave as a collections DSL

• Immutable by default, great for parallel deployments

• Java

• Scala

Page 54: Software Engineering Thailand: Programming with Scala

Collections Classes• Scala Collections are what brought me to the language

• Designed to consistently behave as a collections DSL

• Immutable by default, great for parallel deployments

• Java

• Scala

• Don't get the wrong idea here! Rolling a one-liner into a println is not what I'd call "good style". Instead, note how the functional transparency and type inferencing allows us to inline functions as easily as we can assign them to variables.

Page 55: Software Engineering Thailand: Programming with Scala

Pattern Matching

Page 56: Software Engineering Thailand: Programming with Scala

Pattern Matching

• Partial Functions – A function that is only defined for specific input values

Page 57: Software Engineering Thailand: Programming with Scala

Pattern Matching

• Partial Functions – A function that is only defined for specific input values

Page 58: Software Engineering Thailand: Programming with Scala

Pattern Matching

• Partial Functions – A function that is only defined for specific input values

• Regular Expressions – Please enjoy them now! 😉

Page 59: Software Engineering Thailand: Programming with Scala

Pattern Matching

• Partial Functions – A function that is only defined for specific input values

• Regular Expressions – Please enjoy them now! 😉

Page 60: Software Engineering Thailand: Programming with Scala

Obvious Correctness

Page 61: Software Engineering Thailand: Programming with Scala

Obvious Correctness• Trick question: Which of these is more obviously correct?

Page 62: Software Engineering Thailand: Programming with Scala

Obvious Correctness• Trick question: Which of these is more obviously correct?

• Java:

Page 63: Software Engineering Thailand: Programming with Scala

Obvious Correctness• Trick question: Which of these is more obviously correct?

• Java:

• Scala:

Page 64: Software Engineering Thailand: Programming with Scala

Obvious Correctness• Trick question: Which of these is more obviously correct?

• Java:

• Scala:

• Depends on experience!!

Page 65: Software Engineering Thailand: Programming with Scala

Team Evolution w/ Scala

Page 66: Software Engineering Thailand: Programming with Scala

Team Evolution w/ Scala

• Start with this:

Page 67: Software Engineering Thailand: Programming with Scala

Team Evolution w/ Scala

• Start with this:

• To get to this:

Page 68: Software Engineering Thailand: Programming with Scala

Team Evolution w/ Scala

• Start with this:

• To get to this:

• Make the transition gradually! Do it together as a team!

Page 69: Software Engineering Thailand: Programming with Scala

What does all this buy us?

Page 70: Software Engineering Thailand: Programming with Scala

What does all this buy us?• Pure functions have no side effects... data in, data out

Page 71: Software Engineering Thailand: Programming with Scala

What does all this buy us?• Pure functions have no side effects... data in, data out

• Objects maintain state. This is why Scala is not considered a purely functional language!

Page 72: Software Engineering Thailand: Programming with Scala

What does all this buy us?• Pure functions have no side effects... data in, data out

• Objects maintain state. This is why Scala is not considered a purely functional language!

• When objects are immutable though, the state acts as constants in the functions. Constants are thread-safe!

Page 73: Software Engineering Thailand: Programming with Scala

What does all this buy us?• Pure functions have no side effects... data in, data out

• Objects maintain state. This is why Scala is not considered a purely functional language!

• When objects are immutable though, the state acts as constants in the functions. Constants are thread-safe!

• Immutable objects do not need to be locked. Locking is actually very expensive and error prone

Page 74: Software Engineering Thailand: Programming with Scala

What does all this buy us?• Pure functions have no side effects... data in, data out

• Objects maintain state. This is why Scala is not considered a purely functional language!

• When objects are immutable though, the state acts as constants in the functions. Constants are thread-safe!

• Immutable objects do not need to be locked. Locking is actually very expensive and error prone

• Immutable state is updated by replacing the object!

Page 75: Software Engineering Thailand: Programming with Scala

But it looks so complex!

Page 76: Software Engineering Thailand: Programming with Scala

But it looks so complex!• Scala actually has a smaller grammar than Java

Page 77: Software Engineering Thailand: Programming with Scala

But it looks so complex!• Scala actually has a smaller grammar than Java

• Functional composition (the ability for one function to feed another) allows intermediate variables to be removed.

Page 78: Software Engineering Thailand: Programming with Scala

But it looks so complex!• Scala actually has a smaller grammar than Java

• Functional composition (the ability for one function to feed another) allows intermediate variables to be removed.

• Scala ends up looking complex because developers collapse code that maybe shouldn't be collapsed.

Page 79: Software Engineering Thailand: Programming with Scala

But it looks so complex!• Scala actually has a smaller grammar than Java

• Functional composition (the ability for one function to feed another) allows intermediate variables to be removed.

• Scala ends up looking complex because developers collapse code that maybe shouldn't be collapsed.

• Program so your code is readable, not so it fits in as few lines as possible.

Page 80: Software Engineering Thailand: Programming with Scala

But it looks so complex!• Scala actually has a smaller grammar than Java

• Functional composition (the ability for one function to feed another) allows intermediate variables to be removed.

• Scala ends up looking complex because developers collapse code that maybe shouldn't be collapsed.

• Program so your code is readable, not so it fits in as few lines as possible.

• Occam's Razor: We should reduce to the simplest possible outcome, and no simpler!

Page 81: Software Engineering Thailand: Programming with Scala

Some things haven't changed

Page 82: Software Engineering Thailand: Programming with Scala

Some things haven't changed• TDD – Use it! Create unit tests for everything, use them as documentation

Page 83: Software Engineering Thailand: Programming with Scala

Some things haven't changed• TDD – Use it! Create unit tests for everything, use them as documentation

• One liners should have a simple comment describing what they do

Page 84: Software Engineering Thailand: Programming with Scala

Some things haven't changed• TDD – Use it! Create unit tests for everything, use them as documentation

• One liners should have a simple comment describing what they do

• Frequent code reviews! Pull requests that receive no comments are to be avoided.

Page 85: Software Engineering Thailand: Programming with Scala

Some things haven't changed• TDD – Use it! Create unit tests for everything, use them as documentation

• One liners should have a simple comment describing what they do

• Frequent code reviews! Pull requests that receive no comments are to be avoided.

• Avoid learning a new technique and immediately using it everywhere.

Page 86: Software Engineering Thailand: Programming with Scala

Some things haven't changed• TDD – Use it! Create unit tests for everything, use them as documentation

• One liners should have a simple comment describing what they do

• Frequent code reviews! Pull requests that receive no comments are to be avoided.

• Avoid learning a new technique and immediately using it everywhere.

• If you are the only person that can maintain your code, you will be cursed to own it forever.

Page 87: Software Engineering Thailand: Programming with Scala

Some things haven't changed• TDD – Use it! Create unit tests for everything, use them as documentation

• One liners should have a simple comment describing what they do

• Frequent code reviews! Pull requests that receive no comments are to be avoided.

• Avoid learning a new technique and immediately using it everywhere.

• If you are the only person that can maintain your code, you will be cursed to own it forever.

• If you can inspire others to read your code because it is both short and people "learn one new thing" (only one!), you will be able to move the team forward with new techniques, do more with less, have fun!

Page 88: Software Engineering Thailand: Programming with Scala

I'm not sold yet...

Page 89: Software Engineering Thailand: Programming with Scala

I'm not sold yet...

• Take Coursera's Scala class taught by Martin Odersky

Page 90: Software Engineering Thailand: Programming with Scala

I'm not sold yet...

• Take Coursera's Scala class taught by Martin Odersky

• You will become a better Scala programmer

Page 91: Software Engineering Thailand: Programming with Scala

I'm not sold yet...

• Take Coursera's Scala class taught by Martin Odersky

• You will become a better Scala programmer

• You will become a better Java programmer

Page 92: Software Engineering Thailand: Programming with Scala

I'm not sold yet...

• Take Coursera's Scala class taught by Martin Odersky

• You will become a better Scala programmer

• You will become a better Java programmer

• You will become a better programmer

Page 93: Software Engineering Thailand: Programming with Scala

I'm not sold yet...

• Take Coursera's Scala class taught by Martin Odersky

• You will become a better Scala programmer

• You will become a better Java programmer

• You will become a better programmer

• Apple's Swift language is a bit of a knockoff

Page 94: Software Engineering Thailand: Programming with Scala

I'm not sold yet...

• Take Coursera's Scala class taught by Martin Odersky

• You will become a better Scala programmer

• You will become a better Java programmer

• You will become a better programmer

• Apple's Swift language is a bit of a knockoff

• Get two platforms for the price of one!

Page 95: Software Engineering Thailand: Programming with Scala

How Do I Get Started?

Page 96: Software Engineering Thailand: Programming with Scala

IDEs: IntelliJ vs. Eclipse

Page 97: Software Engineering Thailand: Programming with Scala

IDEs: IntelliJ vs. Eclipse

Page 98: Software Engineering Thailand: Programming with Scala

IDEs: IntelliJ vs. Eclipse

Page 99: Software Engineering Thailand: Programming with Scala

IDEs: IntelliJ vs. Eclipse

• They both have advantages. Each team should "bake off" and doc the results

Page 100: Software Engineering Thailand: Programming with Scala

IDEs: IntelliJ vs. Eclipse

• They both have advantages. Each team should "bake off" and doc the results

• Don't be restricted to one, but a common denominator of skills is helpful         

Page 101: Software Engineering Thailand: Programming with Scala

Testing

Page 102: Software Engineering Thailand: Programming with Scala

Testing• ScalaTest is standard

Page 103: Software Engineering Thailand: Programming with Scala

Testing• ScalaTest is standard

• Behavior Driven Development

Page 104: Software Engineering Thailand: Programming with Scala

Testing• ScalaTest is standard

• Behavior Driven Development

• Use with TDD, just works!

Page 105: Software Engineering Thailand: Programming with Scala

Testing• ScalaTest is standard

• Behavior Driven Development

• Use with TDD, just works!

• The power is in the Matchers

Page 106: Software Engineering Thailand: Programming with Scala

Development Environments

Page 107: Software Engineering Thailand: Programming with Scala

Development Environments• REPL (Read-Eval-Print Loop) is an interactive shell

Page 108: Software Engineering Thailand: Programming with Scala

Development Environments• REPL (Read-Eval-Print Loop) is an interactive shell

• scalac compiler can be run from command line like javac

Page 109: Software Engineering Thailand: Programming with Scala

Development Environments• REPL (Read-Eval-Print Loop) is an interactive shell

• scalac compiler can be run from command line like javac

• SBT is Scala's own build tool, allows Scala code to be used within build, but not very IDE friendly.

Page 110: Software Engineering Thailand: Programming with Scala

Development Environments• REPL (Read-Eval-Print Loop) is an interactive shell

• scalac compiler can be run from command line like javac

• SBT is Scala's own build tool, allows Scala code to be used within build, but not very IDE friendly.

• Maven has a Scala plugin, but comes with all of Maven's idiosyncrasies.

Page 111: Software Engineering Thailand: Programming with Scala

Development Environments• REPL (Read-Eval-Print Loop) is an interactive shell

• scalac compiler can be run from command line like javac

• SBT is Scala's own build tool, allows Scala code to be used within build, but not very IDE friendly.

• Maven has a Scala plugin, but comes with all of Maven's idiosyncrasies.

• SBT can use Maven central repository, but is designed for Ivy repositories. Both end up being required, which is a pain point.

Page 112: Software Engineering Thailand: Programming with Scala

Development Environments• REPL (Read-Eval-Print Loop) is an interactive shell

• scalac compiler can be run from command line like javac

• SBT is Scala's own build tool, allows Scala code to be used within build, but not very IDE friendly.

• Maven has a Scala plugin, but comes with all of Maven's idiosyncrasies.

• SBT can use Maven central repository, but is designed for Ivy repositories. Both end up being required, which is a pain point.

• All the cool kids use SBT, but it's not as mature and harder to use with projects that span multiple source repositories, also not as simple for tagged release environments.

Page 113: Software Engineering Thailand: Programming with Scala

Development Environments• REPL (Read-Eval-Print Loop) is an interactive shell

• scalac compiler can be run from command line like javac

• SBT is Scala's own build tool, allows Scala code to be used within build, but not very IDE friendly.

• Maven has a Scala plugin, but comes with all of Maven's idiosyncrasies.

• SBT can use Maven central repository, but is designed for Ivy repositories. Both end up being required, which is a pain point.

• All the cool kids use SBT, but it's not as mature and harder to use with projects that span multiple source repositories, also not as simple for tagged release environments.

• Verdict: If you already use Maven, stick with it, otherwise use SBT.

Page 114: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution Part 2

Page 115: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution Part 2

• Use Akka – http://akka.io

Page 116: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution Part 2

• Use Akka – http://akka.io

• Scala and Java APIs, Scala easier to use via immutables

Page 117: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution Part 2

• Use Akka – http://akka.io

• Scala and Java APIs, Scala easier to use via immutables

• Message passing pattern without all the JMS overhead

Page 118: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution Part 2

• Use Akka – http://akka.io

• Scala and Java APIs, Scala easier to use via immutables

• Message passing pattern without all the JMS overhead

• 50 million msg/sec on a single machine + small memory footprint; ~2.5 million actors (message endpoints) per GB of heap

Page 119: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution Part 2

• Use Akka – http://akka.io

• Scala and Java APIs, Scala easier to use via immutables

• Message passing pattern without all the JMS overhead

• 50 million msg/sec on a single machine + small memory footprint; ~2.5 million actors (message endpoints) per GB of heap

• Remoting can scale to tens of thousands of machines

Page 120: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution Part 2

• Use Akka – http://akka.io

• Scala and Java APIs, Scala easier to use via immutables

• Message passing pattern without all the JMS overhead

• 50 million msg/sec on a single machine + small memory footprint; ~2.5 million actors (message endpoints) per GB of heap

• Remoting can scale to tens of thousands of machines

• Akka Streams focuses on streaming messages, uses standard TCP facilities to throttle clients, avoid buffer overflows

Page 121: Software Engineering Thailand: Programming with Scala

Concurrency & Distribution Part 2

• Use Akka – http://akka.io

• Scala and Java APIs, Scala easier to use via immutables

• Message passing pattern without all the JMS overhead

• 50 million msg/sec on a single machine + small memory footprint; ~2.5 million actors (message endpoints) per GB of heap

• Remoting can scale to tens of thousands of machines

• Akka Streams focuses on streaming messages, uses standard TCP facilities to throttle clients, avoid buffer overflows

• 2014Q1 test reached 2400 nodes as well as starting up a 1000 node cluster in just over four minutes on Google App Engine.

Page 122: Software Engineering Thailand: Programming with Scala

Who's using it?

Page 123: Software Engineering Thailand: Programming with Scala

Who's using it?

Just about every major player has something in Scala:

• Apple

• Intel

• Twitter

• Agoda

• Airbnb

Page 124: Software Engineering Thailand: Programming with Scala

Who's using it?

Just about every major player has something in Scala:

• Apple

• Intel

• Twitter

• Agoda

• Airbnb

And any company using these scaling technologies:

• Apache Spark

• Apache Scalding

• Apache Kafka

• Twitter Finagle

• Typesafe Akka

Page 125: Software Engineering Thailand: Programming with Scala

Lessons?

Page 126: Software Engineering Thailand: Programming with Scala

• Every developer has the power to enlighten or obfuscate

Page 127: Software Engineering Thailand: Programming with Scala

• Every developer has the power to enlighten or obfuscate

• Complexity has many different measures at many different levels. The solution of least overall complexity often hides behind greater surface complexity!

Page 128: Software Engineering Thailand: Programming with Scala

• Every developer has the power to enlighten or obfuscate

• Complexity has many different measures at many different levels. The solution of least overall complexity often hides behind greater surface complexity!

Page 129: Software Engineering Thailand: Programming with Scala

• Every developer has the power to enlighten or obfuscate

• Complexity has many different measures at many different levels. The solution of least overall complexity often hides behind greater surface complexity!

• On first glance, Functional Programming looks difficult, but hundreds of years of proven advanced math are what built society – bridges, buildings, cars, computers

Page 130: Software Engineering Thailand: Programming with Scala

• Every developer has the power to enlighten or obfuscate

• Complexity has many different measures at many different levels. The solution of least overall complexity often hides behind greater surface complexity!

• On first glance, Functional Programming looks difficult, but hundreds of years of proven advanced math are what built society – bridges, buildings, cars, computers

• Why reinvent that wheel? Allow mathematical induction to help your efforts.

Page 131: Software Engineering Thailand: Programming with Scala

• Every developer has the power to enlighten or obfuscate

• Complexity has many different measures at many different levels. The solution of least overall complexity often hides behind greater surface complexity!

• On first glance, Functional Programming looks difficult, but hundreds of years of proven advanced math are what built society – bridges, buildings, cars, computers

• Why reinvent that wheel? Allow mathematical induction to help your efforts.

• Moore's Law has given us blessings, including the ability to use increasingly complex compilers.

Page 132: Software Engineering Thailand: Programming with Scala

References + Q&A• Scala Course:

https://www.coursera.org/course/progfun

• Please read chapter 1, available for free: http://manning.com/kuhn/

• Twitter's Scala School:http://twitter.github.io/scala_school/

• Scala Cheat Sheet : http://mbonaci.github.io/scala/

• Deeper insight:http://danielwestheide.com/scala/neophytes.html