Opening speech by Miles Sabin about Si-2712. If this tells nothing to you then you are with me. I just learned it is about some rather obscure type handling that wasn’t properly implementes in Scala. The speech is about what he did to add this feature to the language. The solution being to branch the compiler and modify it. So if you want the feature, you need to use a different compiler (meaning not a completely new compiler written from scratch, but the lightbend compiler patched).
Surely I’m not enough in functional programming to fully appreciate the need, but maybe an opening speech could have been more general of at least more appealing to a broader audience.
Scala is the next Scala. Reasons to adopt Scala. Quick history of Scala in the enterprise. Interesting, but not enlighting. Starting by saying everything is an opinion is not something that make you willing to rely on that.
example: article service. Declares a good to be sellable at a given price. Must integrate with other micro services. Time to market is the key, but maybe not everything is available.
Components: cut the system into pieces. The primary criteria is what a compjent is capable to hide.
DI – cake pattern? Guice? Spring? Yes but something new: constructor injection.
What’s wrong with this?
Reader is something the reads something and transforms into something else. Using shapeless you can have implicit readers and everything works without the need of writing anything.
Annotations can trim down the need for code.
Rho can generate swagger files from code.
For each interface you need to provide at least one default implementation. It makes sense to have one default implementation for each interface you have.
This is good, but you need to write a reader that provides the configuration.
Unit test is very easy because you put mock objects in the constructors.
Integration testing is not so simple, because you want some dependencies are resolved by default and some other are to be linked to mock up.
Dependencies tree can be rewritted. Kiama is a library for compilers that provides way to rewrite trees.
Replace is a kiama algo that can be used to replace the object you want to replace with mocks.
Singletons. Some nodes are not to be replicated, so dependencies is not strictly a tree. But I can handle it with replace to turn a tree into a graph.
You can display the graph of the application so you cab check the application dependency graph.
Lazy + start interface – walking the tree each component is started.
EFF. Even if you do FP components are not dead.
Methods can have been defined not very precise. EFF mondads combine a return value and some effects.
Either is an EFF monads. You get one branch or another and they can be chained.
In this way you can force the programmer to run a number of actions in order to extract the result of a function.
Logging and testing. By using is approach to testing you avoid the need of trimming down logs for components not under test.
Mistakes- stack. Clients are invoking methods when they are not ready. Always
Error handling. Use just one error handling type to avoid conversion.
Use local effect.
DSL to eliminating boilerplate. Time consuming and difficult.
There are macros and shapeless. Which one? How to integrate?
Constructing values. We have a case class and an we want to produce an instance without specifying the parameters .
Macro takes a type and produces a syntax tree.
Some 40 loc
Shapeless converts a type into an anonymous list of types. You can traverse the list and computing algorithm.
Code is 16 loc and doesn’t deal with syntax, but with types structure.
Error messages are cryptic , maybe fixed in dotty.
Compile times can be expensive because an implicit lookup is performed.
Akka is a toolkit, it doesn’t frame you, so you can hurt yourself.
If you want to make enemies, try to change something (w.Wilson)
It’s OK for an actor to have a mutable state as long as it keeps control to it. The actor can leak state by giving away references to internal states. Closing over mutable in async. Taking reference in constructor.
Dispatcher is what makes akka tick. It takes a thread and assigns it to an actor to perform some messages. Then it passes the thread to another actor. You don’t control which thread is assigned to your actor. In some cases it may makes sense to use a pinned dispatcher (thread permanently assigned to an actor).
What to do: use immutable messages for updates and broadcast. Use queries to get state info from an actor. For async always use pipes.
Anti pattern 2. If your actor system has no hierarchy you are missing the point. Hierarchy handles the failures. No hierarchy means no failure handling.
What java does on exception catching. The 3rd more common is doing nothing.
Akka requires you do something – an exception makes the actor crash and the parent needs to decide what to do.
Errors should be handled out of band, not in the main application. This is implemented in the concept of supervisor in akka design.
So you need hierarchies.
3rd anti pattern. Too many actor systems.
The intent may be good if it is the intent to insulate things. Each actor system is expensive because it has a thread pool. All the pools contend the same resources.
Keep calm and trust akka. By using dispatchers you can shape the number of threads per actor groups.
Anti pattern – logging
Logging is one of the main reasons for poor performances. String concatenation and composing data from slow sources . non async logging. Keeping debug log on in production. 2017 you should not log to file, but to a centralized log server.
Actor systems are meant to process million s of messages per second. Use akka log facility. Configure properly appenders. Use string interpolation.
Anti pattern: out of touch with hw. JVM inside a VM inside a kubernetes. How many cores the machine has is an useful information for properly tune threads and dispatching.
Cost of context switch.
So know your he and properly configure it. Beware of VM.
Run load tests on the same he you use on target.
Anti pattern: blocking.
You may call a sync api. Waiting for the completion of a future. Using thread.sleep.
For a legacy Api use a dedicated dispatcher optimized for the blocking case.
Always use future with pipe pattern
Use the akka scheduler to wait for something.
Anti pattern rewriting akka tools. Maybe you didn’t read all the doc. Reinventing back off supervision. Reinventing message prioritization (use mailbox).
This is bad because it make you waste your time.
What to do: read doc, call consultant.
Anti pattern : using Java serialization.
This is bad because of poor performance. It is poor for protocol evolution (it can happen also in serialization).
Use proper binary format.
Use protobuf, avro or thrift.
Why monads? Effects and sequence.
Also they help to raise the abstraction level.
E.g. advertising service. One of the advantage is that you don’t care too much about the specific concrete type you are using. Monoids and algebra let you focus on processing.
Keyword expander is a function that turns in future of keyword