Scala

Scala Patterns To Avoid: Implicit Arguments With Default Values

There is a tendency for the Scala projects to prefer more explicit programming style. The biggest aspect of that is in my opinion the type system of the Scala language, programmers often start writing their functions by defining types of the arguments and type of the result, only to write the body of the function as last step. That’s also because we have the Scala compiler to help us. I recently stumbled on a snippet that contradicts this rule and can be a source of hard to spot bugs for the person unfamiliar with the code.

Simple way to create Scala scripts

This post is a description of a small project idea developed by a friend of mine: Przemysław Pokrywka, I’m just writing down the idea as a blog post. There are many ways one can execute Scala code, most people use sbt to create a some kind of build, for example fat jar or something similar or just sbt-native-packager to build the application in more native formats. But what options do you have in case you want to write Scala scripts?

Testing Akka Performance

Few weeks ago I attended a workshop called “Understanding Mechanical Sympathy” ran by Martin Thompson. During that workshop we written and tested few concurrent programming techniques and as a first exercise we have written a simple Ping-Pong program: package uk.co.real_logic; import static java.lang.System.out; /* Original exercise did during "Lock Free Workshop" by Martin Thompson: http://www.real-logic.co.uk/training.html */ public final class PingPong { private static final int REPETITIONS = 100_000_000; private static volatile long pingValue = -1; private static volatile long pongValue = -1; public static void main(final String[] args) throws Exception { final Thread pongThread = new Thread(new PongRunner()); final Thread pingThread = new Thread(new PingRunner()); pongThread.

JSON in Play Framework - Advanced Libraries

This is a followup post to my previous one covering JSON in Play framework. I’d like to show how the manual work I did before in trying to make JSON mapping compatible with external API can be done by using 2 small but useful libraries: [play-json-naming](https://github.com/tototoshi/play-json-naming) [play-json-extensions](https://github.com/xdotai/play-json-extensions) play-json-naming This is a very simple library that can be used to convert from camelCase formatting (the default one that we use in Scala) to snake_case formatting that is common in various different languages (for example PHP or Ruby).

JSON in Play Framework - Techniques For Making Compatible Mappings

I’ll show 2 slightly advanced techniques for working with JSON in Play Framework (play-json) that are useful especially when you need to control the mappings yourself. For example when you have to make sure that your API is compatible with existing applications. The examples are based on my project Game Arena (which is in very early stages of development) One suggestion, before we start, take a look at Play Framework JSON documentation which is truly quite comprehensive and provides a very good introduction to JSON usage in Play.

Scala Case Classes vs Enumeration

After my previous post which was received quite nicely, I wanted to write a little bit more about the topic of designing Typesafe Domain objects, this time I’ll focus on the problem of how to model a deck of cards in Scala. I’ll go over 2 different approaches you might take when designing a solution to the problem of card games in Scala. I’ll try to show how this can be done with Case Classes (Sealed Case Objects) and Enumerations.

Typesafe Domain Objects in Scala

Today I’d like to cover the topic of how to approach type safety in Scala in case of the simple domain of players in free to play games - this is a real example from a past project of mine. If you have played any of the free to play online games, you are already aware that these games every often have 2 kinds of currencies: In game cash or points that can be earned and spent during the game play

Running Playframework! on Raspberry Pi

Recently I wanted to see if it’s possible to run applications written in Scala and Playframework! on my Raspberry Pi 1. Java installation My Raspi was installed from raspbian image which had java already installed, if you need to install it yourself you can either do that manually (remember to choose ARM package) or use automated script like, OAB-Java ( https://github.com/flexiondotorg/oab-java6 ) 2. Build application locally This step doesn’t differ on raspi, the command is the same