Scala · Tutorial

How to use Case Classes in Scala

Scala has adopted many concepts from other functional programming languages: higher-order functions from Haskell, actors model from Erlang, futures from Clojure, etc. However, Scala has also introduced new tools in the functional programming world: case classes is one of them. Case classes are a special type of classes, as the compiler automatically adds some useful… Continue reading How to use Case Classes in Scala

Akka

Akka Actors: Best Practices

Actors are components of message-passing systems that are particularly popular these days. They make concurrency a lot easier to understand compared to the traditional thread-monitor-lock model. An actor is a thread-like program that run independently from other actors. It has a mailbox to receive messages from other actors, where each message represents a task to… Continue reading Akka Actors: Best Practices

Scala · Tutorial

Stateful objects: use them to lie!

Sometimes we want to hide/protect our variables — the classic concept of encapsulation in object oriented programming. We’d like to write a Scala class to manage someone’s age. In particular, we’d like to: - lie on our age if we are not teens anymore (you never know!) - put some validation to avoid negative age values Our… Continue reading Stateful objects: use them to lie!

Scala

Super Powers to Qualified Access Modifiers

Scala uses access modifiers quite differently from Java. Let’s see what the differences are and why qualified access modifiers are so powerful in Scala. default access modifier Scala >> public Java >> protected While in Scala the public keyword doesn’t exist, Java allows you to explicitly use the keyword protected as you please. private Scala >> accessible from a class and its companion… Continue reading Super Powers to Qualified Access Modifiers

Scala · Tutorial

Shared package code? Fear no more!

Sometimes code is common to all the classes of a specific package (e.g.: conversions between objects, custom logs, shared operations, etc). Our lovely Java doesn’t seem to have a convenient way of declaring code as part of a package, rather than just a class….but FEAR NO MORE! Let’s see how we can this in Scala using package objects.… Continue reading Shared package code? Fear no more!