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.

Eff monads

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.

Avoid DSL



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

*m*zn bye bye

One week ago I received an email from the most successful online store owned by Bezos, telling me that since my site didn’t earn any money in the last 365 days, my affiliation program was terminated. Within a week I had to remove all references to their website from my blog.

Here is the text of the communication:

Il tuo account da affiliato verrà chiuso con effetto entro il termine di sette giorni, entro lo stesso termine terminerà anche l’ Accordo Operativo che lo regola.

Nota – Questa comunicazione riguarda solo l’account elencato nella riga dell’oggetto di questa email.

Perché questa comunicazione?
Perché non sono state effettuate vendite tramite link di affiliazione negli ultimi 365 giorni.

Cosa accade ora?
Dovrai terminare l’utilizzo di ogni contenuto e marchio *m*zon e rimuovere immediatamente tutti i link diretti al sito di *m*zon. Riceverai tuttavia il pagamento per ogni commissione ancora da pagare guadagnata precedentemente a questa comunicazione.

Ti invitiamo tuttavia a candidarti nuovamente in futuro visitando la pagina: https://programma-affiliazione.*m*

Ti ringraziamo per la partecipazione al Programma di Affiliazione di *m*zon EU.


I sent them two emails, one to the Italian branch and the other to the US headquarters, stating that mine is not an e-commerce website and my affiliation is more a service to my readers to look up books and/or movies if they are interested (in fact is far more than 365 that referral fees sum up to 0). Despite the claim of a reply in less than 24h I got no response.

Basically, I don’t understand why they have to behave like this, the traffic from my website costs them zero. Also, any traffic that would arrive there could be a potential purchase (this is more up to them to be good at marketing on their website). But also it piss me off that I have to remove all links to their website – I had to go through the database of my website (15 years of posts) and manually replace references. And why? Shouldn’t I be free to link anyone I want to link?

So I decided that *m*zn is history, time to look elsewhere. I would like to join the affiliation program of ibs, but I still have some trouble with their affiliation service tradedoubler.

Garbage-Collecting Garbage

Here we go again, another system written in one of the advanced languages that promise to avoid you the burden of memory management, another unavoidable performance issue and yet again another desperate run to move everything out of garbage man hands into a set of dedicated memory pools.

According to Wikipedia, GC (Garbage Collection) was invented back at the dawn of computer science, (ca 1959) for the LISP language. Since its inception, GC made promptly clear that it didn’t play well with time constraints (see Humorous Annedoct in History of Lisp).

Read moreGarbage-Collecting Garbage

Java Magic Trick

One of the (many?) shortcomings of Java is, at least in my humble opinion, the lack of unsigned integers. This may seem a minor problem, but it becomes a real annoyance when you have to deal with bits and bytes.

Consider the right shift. As a good C/C++ programmer you know that right shifting of a signed integer is generally bad. Java defined two bit-wise right shift operators: >> and >>>. The first extends the sign, so that -2 >> 1 evaluates to -1 and -2 >>> 1 evaluates to (-1 & 0x7FFFFFFF), i.e. the left most bit that becomes vacant pending the shift is filled with a 0.

So far, so good. So you may be surprised from the result of the following code:

class Surprise
    public static void main( String[] args )
        int result = -1 >>> 32;
        System.out.println( "surprise: "+result );

I don’t want to spoil the result, so you may want to take some more time to think… Ready with your guess?

Well prints -1. That’s because the right hand side argument of the >>> operator is masked implicitly by 0x1F (i.e. taking values just between 0 and 31 included).

No warning is emitted during compilation, so you are pretty on your own – either you know or you don’t and trouble are ready to … byte you.

What is in a name?

Here now and then, as a programmer, you have a hard time finding a good name for something. That thingy thing that eludes your wit and skill to name things. And that’s bad because it is hard to reason about unnamed entities. Symbols are deeply embedded in our brainwork and the right word has quite a power to drive thoughts efficiently and reliably.

Read moreWhat is in a name?

If the free lunch is over, where can we eat for free?

In the first part of this blog post, I wrote about why FP is mandatory for programmers that work on modern software projects. Summing it up, it was like this – modern hardware scales up by adding cores, therefore, if software wants to scale up and well, then it has to do it by going concurrent, and FP is a good choice to deal with concurrent programming issues.

In this post, I’ll write about some differences between traditional and FP programming and I’ll present one more reason about why FP is a good match with parallel programming.

You can write bad code in any language. That’s a fact. So there’s no magic in functional programming to turn a lame programmer in a brilliant one. On the other hand, you can write pretty good code in the functional paradigm by sticking with the tools provided by functional languages.

So, let’s have a look at this FP thing… First, it is evident that this is not your parent’s FP – map, filter, fold… Just a few of the most recurring spells you’d see in a Scala source and none of them was in the notes I jotted down during my University courses. Even looking at my LISP textbook I couldn’t find any reference to the map operation. (Just to help those with no FP background – map (transform in C++) is an operation that applies a transformation to each item in a collection. In other words, if you have a function that turns apples into pears, then – using map – you can turn your array of apples into an array of pears.)

Read moreIf the free lunch is over, where can we eat for free?

Lambda World 2018

Back in the XVI century, the Flota de Indias based in Cadiz set out to Americas carrying tools,  books, and settlers and carried back goods, from the new world.

In much the same way I went to Cadiz and set off for the brave new world of functional programming with the intent of carrying back news and techniques for my daily job.

Cadiz is an awesome and is a wonderful frame for one the best conference I attended in 2017 and 2018 – Lambda World.

As usual, I took a lot of notes and possibly soon or later they will land here. I plan to prepare a short summary with information about the conference and briefs of the speech I attended, much I did for Scala Italy. In the meantime, I warmly suggest these awesome notes (by Yulia). Stay tuned.

Scala Italy 2018

At the end of September, my employer sent me to the awesome city of Florence to attend the Scala Italy conference. Thanks to this patronage, this is the third year I’m able to be at the conference of the Italian Scala Community.

For the first time this year, the conference lasted two days with two distinct tracks – talks and workshops. The choice of one working and one non-working day can be a bit odd and likely a symptom of some ambivalence about the target audience. To keep the conference for Scala enthusiasts attending in their spare time or to move it to the professional realm, that’s the question. Given that the ticket price wasn’t very light on pockets, maybe half of the decision has already been made.

I dutifully took notes during all the talks so I’d like to prepare some posts with my notes. I noted that after I did so for ++it 2018 (Channels are Useful, not only for Water, Zero Allocation and No Type Erasure Futures, Time Travel Debug, ++it 2018 – Coroutines – coming soon… ?, ++it 2018 – Key Notes) conference organization put all the conference videos online. I’m pretty sure the same is going to happen for Scala Italy 2018 as well. So I’ll wait for your feedbacks before investing the time needed for writing all the blogs.

Read moreScala Italy 2018

Is Functional Programming functional to programming?

Some 25 years ago I took my class of advanced programming which included exotic paradigms such as logic and functional programming.

As most of the content of that course, FP went into a seldom-if-ever open drawer during my professional career.

Simply I never saw the needs to use Lisp or had the luxury to afford never changing values.

A few years ago (well not that few – just checked it was 2005) I read on DDJ that the free lunch was over. That has nothing to do with the charitable food bank, but it marked a fundamental twist in the computer performance evolution. Something that would have a strong impact on how software was going to be designed, written and tested.

Until 2005 no matter how your code was badly written and underperforming. You were assured that for free, just waiting for the next hardware iteration, your code would have run faster (bugs included)! This is like deflation in economics – why should I invest my money if keeping them in the matters for a year they increase their value?

Read moreIs Functional Programming functional to programming?