Skip to main content

Posts

Showing posts from April, 2018

Scala - Actors, or Back From Functional Programming to Object Oriented Programming

I started my Scala journey 7 years ago in a pragmatic way compared to the functional programming enthusiasts of nowadays (although a research lab made me program a media player using only XSLT — you can't get anymore functional than that!). At the time I had written a few Java programs of medium complexity and I often bumped into the limitations of object oriented programming.

Modeling everything as objects — with their promise of encapsulation — seems nice and tidy in theory but, as the size of the program grows, side effects create unforeseen interactions. I found it easier to reason in terms of immutable data and functions, which led me to write my programs in a more functional way over time.

Fast-forward to the present day and Scala has now become partly synonymous with Akka Actors which, with their message passing semantics and encapsulated internal state, are a new incarnation of object oriented programming.

Granted, it does not include inheritance and its associated pitfall…

Scala - ClassTag and TypeTag Performance Penalty

If you program in Java, you probably know that the compiler performs type erasure for performance and backwards compatibility reasons. Thus, parameterized types of generic collections are normally not accessible (although you can work around the limitation using reflection or by passing the class  explicitly).

Scala comes with the concept of ClassTag and TypeTag which enable you to enrich the accessible type information. Using type bounds, it makes it easy to access type information at runtime.

However, using ClassTags and TypeTags requires importing from scala.reflect. Does this mean that it uses reflection, a scary thought when considering performance? Here is a quick unscientific benchmark to figure things out with Scala 2.12.4:


As you can see, using ClassTags incurs no performance penalty compared to case class pattern matching. On the other hand, TypeTags is significantly slower due to it bringing along richer type information. Only use the latest if you really need it!

The Engineering Mindset Overreliance Error

In my previous startup life, I built a web application which purpose was to help companies screen applicants during the recruitment process, so that they could recruit employees that were the best fit for them. Our product was quite innovative in the sense that it matched the personality of applicants with the culture of the recruiting company. In order to do that, we would first send questionnaires to the current employees of the company to determine its culture, and then we used statistics, machine learning, artificial intelligence to compute a fitness score for applicants, based on their answers to their own questionnaire. The idea was well-received and we got a few clients pretty fast.

Problems began we started improving our solution. Reading the scientific literature on recruitment, it soon appeared that IQ was the single most important factor for predicting future performance of employees. As our goal was to help companies recruit the best people for them, it seemed logical for …