Showing posts with label scala. Show all posts
Showing posts with label scala. Show all posts

Wednesday, September 29, 2010

The Strategy pattern and Traits

So I promised I would talk about patterns and traits. When I wrote about the concepts of the Controller and the RuleSet, I already hinted at using the Strategy pattern. I was right, because that turned out to be exactly what I needed. And I was wrong, because the classical Strategy pattern is an ill match for Scala.

In this post I will explain how I implemented the Strategy pattern using Scala traits, and how this turned out to be an unsatisfying approach.

Wednesday, September 22, 2010

My first experience with Scala collections

In my previous post, I explained some concepts for improving my city builder simulations. By now, all code has been implemented, reimplemented, and reimplemented again. This has resulted in a codebase which, in my humble opinion, resembles real Scala. As a bonus, it also does what I wanted it to do.

I will talk about collections, traits, design patterns, and having fun with Scala. This post is dedicated to Scala collections; the traits and design patterns will be discussed in the next post.

Monday, September 6, 2010

Refactoring: Traits and Partial functions

In this post I was planning to add Citizens to my simulation. I did, and it turned out to be as exciting as watching termites mate.

So instead, in this post I will add Citizens to my simulation, clean up my codebase, factor out all duplicate code using Traits and refactor the act/loop/react by introducing partial functions.

Friday, September 3, 2010

Creating a simple simulation - Harvesters

In my previous post, I created a specification for my Harvesters. Now it's time to actually implement them and let them conform to that spec.

This post is mostly about messaging between actors, the different choices in handling those messages, and the impact these choices have on the concurrency of your system.

Wednesday, September 1, 2010

Creating a simple simulation - The HarvesterSpec

In my previous post, I introduced the Producer actor. Now it's time to introduce the Harvester.

In this post I will define the specifications of the Harvester and show how to test the concurrency of the eventual implementation.

In order to do this, I will also dive into some of the cooler features of Scala, especially foreach, map, list-comprehensions and futures.

Adding Scala unit tests

In my previous post, I showed how the Producer worked by adding some example code to my Simulation object. This might be very suitable for small projects, but in the long run I always prefer to have unit tests. In this post I will show how I added Scala unit tests to my project.

Creating a simple simulation - Producers

Now that the project has been set up, it's time to start creating the first steps in our simulation.

Every city simulation game I've played begins the same: getting workers to obtain raw materials. So let's  create a text-only simulation that does just that.

This post is about Scala syntax, Scala Actors, Scala messages, and examples of pattern matching.

Creating a Java/Scala Maven project

In this post, I will explain how I set up my first program, allowing me to create and run an extremely simple Scala program in my favorite IDE using Maven.