A common issue noticed when reviewing pull requests is the understanding of the boundaries of Futures. In most cases, people take for granted that given a function with this signature the full body of the function will be executed in the Future. Let’s look closely into this with a couple of examples Example 1 Here’s …
Tag: scala
How to construct objects in Scala
Scala’s object-oriented programming style comes with some syntactic sugar and a few tricks. In order to get a better understanding of how Scala works, we will examine a few Scala examples and the corresponding byte code (in reality, the Java code resulting from decompiling the class files). Examples Empty class Simplest possible example, an empty …
Scala’s uniform object model
Scala is functional and object-oriented. In a way, Scala is more object-oriented than Java as it has a uniform object model similar to Smalltalk’s. So what is this uniform object model? In a nutshell: every value is an object and every operation is a method call. That’s right, there are no primitive types, i.e. 1 …
Folding things with Functional Programming
Introduction In this post we will discuss the concept of fold in functional programming: fold functions are used to reduce a data structure containing multiple values into a single one. Associated to the idea of fold are the concepts of recursion: via recursion, fold traverses the different elements of the data structure. summarisation: the data …
Read the full post →“Folding things with Functional Programming”
Focus on your data structures with Scala lenses
With new programming techniques come new problems and new patterns to solve them. In functional programming, immutability is a must. As a consequence, whenever it is needed to modify the content of a data structure, a new instance with updated values is created. Depending on how complex the data structure is, creating a copy may …
Read the full post →“Focus on your data structures with Scala lenses”
Unveiling blocking operations
Background Developing an application following the reactive principles can be quite challenging, specially when working with third party libraries, as these may not be fit for purpose, i.e. blocking operations. In such cases, the first challenge is to find the blocking operation and the second to confine it so that it does not affect the rest of the …
Functional programming
This post presents some features of functional programming with Scala. In essence, functional programming is about programming by making use of mathematical functions. All well-known features of functional programming are just a result of using mathematical functions, e.g.: referential transparency immutable state higher-order functions pattern matching I especially like ‘pattern matching’ as it allows for a …
Dealing with memory leaks
Background This post describes my experience playing around with Scala and some of its concepts like tail recursion and futures. It also offers an opportunity to see how a memory leak can happen and how to analyse it. I created a simple web crawler that takes a seed link (e.g. http://www.bbc.co.uk) and then, recursively (using tail recursion), collects all …