Archive for the ‘scala’ Category

CQRS/ES with Scala, Akka and Lift

Wow, more than a year has passed since the last blog post. Time for an update.

When we started creating fleetdna.com, we iterated quickly using the ORM built into Lift: Mapper. It is a fairly simple (in a good way!) ORM based on the Active Record pattern. It comes with builtin support for things like CRUD screens etc. This allowed us to create functionality fast, essential in a new company trying to get a product to market.

Fast forward a few years. As product complexity grows, the simplicity of Mapper and the tight coupling of data to UI was becoming a burden. It was not possible to create the more advanced queries without running into the N+1 problem. We also needed to present and edit information in the UI which is not directly related to single records. Basically we are moving towards a more task based UI.

Continue reading

Developing Lift using Eclipse and the Scala Ide

This is a quick intro to developing Lift (the framework, not applications using Lift). Mostly useful for people wishing to work with the code base (like committers).

Just to reiterate: This is not for developing Lift applications. If you need to navigate the Lift source code (highly recommended btw!), have your build tool of choice download the source jars and attach them to the Lift jars in your project.

Continue reading

Rapid Lift application development with Eclipse and JRebel

In this article I’ll describe the setup I use to do develop Lift applications. While more heavy-weight than if an interpreted language is used, I find this setup provides fairly decent turnaround times.

Continue reading

Lift quick start: Look Ma! No Maven

For the last year or so, I’ve been using the Lift web framework to develop our B2B SaaS application (my experiences can be found here). I’ve enjoyed this very much, especially the community, so when David Pollak asked me to be become a committer I couldn’t say no 🙂

One area where Lift is lacking is in documentation, so I’ll try to write a few posts here that can help people getting started using Lift. I’ll be writing about the workflow we use, since

  1. It works for us
  2. It is not using Maven, a source of some ….. frustration for many

Continue reading

Scala and Lift – Status after six months

There are many choices to be made when starting a new project. In this post I’ll try to explain our technology choices and the experience we’ve had so far.

Background

One of the nice things about starting a new project in a startup is the freedom of choice when it comes to selecting platform and tools. You can spend an awful lot of time mulling between the different choices, but in the end, it is usually not the choice of programming language that kills a startup.

First, a little background. I’ve been programming for more than 15 years in C++,VB,C#, Java,Perl & PHP. The last 5-6 years it has been mostly enterprise Java. When I started at my last job (another startup) we had a product implemented in Java that we turned into a SaaS platform. The core remained in Java  and much of the web frontend was implemented in PHP. I really liked the productivity we got out of PHP as compared to the Java code. Very fast turnaround times. But somehow the language/platform doesn’t really  turn me on.
Continue reading

Beware of Scala’s lazy Range in for/yield

I’m currently using Scala for most of our development and like it a lot. Coming from a mostly Java background, it is nice with a familiar execution environment and tools. But there a few things that has bitten me, one which I just spend almost an hour trying to nail. So I’m posting it here hoping it might save somebody in the future.

Scala has a nice mechanism for creating lists with a for comprehension:

val l = for (...) yield computeResult(...)

Basically, l will become the list of return values from computeResult. Cool.

Scala also has Range class that, together with the for comprehension mimics a standard for-loop construct:

for(i <- 1 to 20) { ... } [/sourcecode]

Problem

I had the following case. I needed to create some objects in a database and return the results in a list. So I created something that looked like the following:

val databaseObjects = for(i <- 1 to 20) yield { val o = CreateObject o } [/sourcecode] When I ran this code, nothing happened?! I checked the DB, no records to be found anywhere. I tried printing the object o inside the loop. Nothing got printed. Tried the construct in the Scala REPL. Everything worked fine. Then I tried printing databaseObjects.length after the loop. Shows that 20 objects were created. Hmmmm. Then I tried printing all elements of databaseObjects. They were created just fine. Hmmmmm. I recalled  a discussion about the Range being created by the expression "1 to 20" is a lazy data structure which is not evaluated before the results are needed. Turns out this lazyness is contagious (more details can be found here)  Ahhhh. Everything makes sense now, since nothing happened until I tried to actually fetch the objects from the list (and the REPL implicitly retrieves the objects to print out the results!)

Solution

The fix is easy, you need to force the lazy range:

val databaseObjects = for(i <- (1 to 20).force) yield { [/sourcecode]