Richard Dallaway

It's mostly technical stuff here. Mostly. 

Slides and video from "Getting Started with Lift"

Yesterday I gave a presentation at lsug.org on "Getting started with Lift".  When I first started looking at Lift I found it quite tricky to grasp what was going on, so I wanted to try to pass on my experiences to help people over any initial humps they may encounter, but also push out to show where you can go with Lift.   So with that in mind, I gave a general overview and then dived in with some live coding.  This turns out to be quite challenging, but with the help of the front row to fix up various errors I made, and the IDE prompting me to fill in some blanks, I just about got there.

You can find the video at Skillsmatter's web site.  You can grab the slides from my talk, but scanning through them a moment ago I noticed that the code I included in the slides and the code I actually typed on the night are quite different.  So I've dumped the code, in the state that it was in at the end of the evening, over on github.

I managed to not mentioned the caveats with the code I was writing, and I missed out a section I was going to do on Box...but... hey, stuff happens. 

 

 

 

Loading mentions Retweet
Filed under  //   events   lift   scala  

Comments [0]

Scala in London in 2010

There's plenty of Scala and Lift events in London this year....

The London Scala User Group (which you can learn about at lsug.org) is running a free event every month of the year. Last night Miles gave an introduction to Scala for Java developers, and the slides are available as a PDF. Next month on Feb 8th, Colin is giving examples of re-writing Java classes in Scala and making your code lovely.

On 8th March I'll be doing a "Getting Started with Lift" session, which you can sign up for at the Skillsmatter site.

There's also...


If you want a peek at what the other LSUG events are being planned for the year, get a Google Wave account and search for the LSUG wave, but join the London Scala User meetup.com group to be emailed the announcements.

Loading mentions Retweet
Filed under  //   events   lift   scala  

Comments [0]

Functional Programming Events

Next week I'll be heading up to the Skillsmatter Functional Programming Exchange event (Mon 7 December 2009). I hoping to learn some good stuff there. The following day there's a BrightArray event where we're going to discuss the paper Why Functional Programming Matters.

Loading mentions Retweet
Filed under  //   events   functional  

Comments [0]

London Java Community Unconference 1

Congratulations to the organizers of the London Java Community: the first unconference was a success.

IBM kindly hosted the event at their Southbank building, and it's a great location for an unconference. It has a set of rooms that are just the right size, but also has a central mingling point where you can meet and chat with people. Possibly for the first time at a conference for me the gaps between the sessions were as useful as the sessions themselves.

I ran a session to discuss what's stopping anyone from using Scala, especially in existing Java projects. Kind of a negative title in some ways, but the point is that I don't see any technical reasons not too as the tool chain is there. I was interested to hear other's experiences. The slides from my session are online, but they were really just put up to help kick start a discussion between the 19 people who were in the room.

It tuns out there's a detailed Google Wave covering this and other sessions, but I'll list the main points that were discussed here:

  • Learning: there seemed to be a reluctance to use Scala until you know "the Scala way" or understand functional styles. It does seem fair to say you'll get more benefit from adopting more of Scala, but I feel that you need to at least start using Scala to understand how it can improve what you do. The point was made that you can start using Scala in a Java-like way (there's absolutely nothing wrong with that), and get some benefits today.
  • What are the benefits? Aside from less code, code that is easier to understand (IMHO), increased developer joy or passion, I pointed to the previous session which covered The Bug of the Month which was a hairy threading-related issue: if you're doing anything with threads, you've probably got it wrong. The actors library in Scala can simplify concurrency.
  • Commercial support: There's no named organization backing Scala. So where does the warm Sun, IBM, Oracle feeling come from for management?
  • What areas is Scala best applied to? That is, what areas of Java would you prefer to use Scala for? The honest answer is all areas. There's no place where you'd prefer Java over Scala.
  • Selling to management: why take the risk? I think it's a case of why miss the opportunity, if you can deliver more reliable results faster, and keep developers happy and engaged.

I suggested—and it's not an original idea—that unit testing might be a place to start as you can improve tests and gain experience. I put an example of that in my slides that I ripped out of some production code just before the presentation.

There were requests for more Scala resources (damn...perhaps I should have done an intro to Scala session too) so here are the resources I've found useful:


In the pub afterwards, there was a Scala corner where the London Scala User Group was reinvigorated. The lsug.org has been recovered and Skillsmatter have kindly offered to host a monthly event, probably on a Wednesday, starting in Jan 2010. Keep an eye on the LJC mailing list for news.

You'll find my photos of the event on Flickr and the hash tag on Twitter is #ljcuc1.

Loading mentions Retweet

Comments [0]

Great functional programming lectures

A few weeks back Miles emailed the BrightArray group with a link to Erik Meijer's Functional Programming Fundamentals lectures. You can find them listed at channel9 tagged as C9 Lectures.

I'm not planning to use Haskell for real, but I wanted to pass the links on because I'm finding the lectures really helpful for thinking about software. Possibly for thinking in general.

Two practical points about the series: you don't have to install silverlight to watch them as there are links to other formats over on the right of the page. And the slides can be found over at Graham Hutton's Programming in Haskell page.

Oh, and don't forget to do the homework.

Loading mentions Retweet
Filed under  //   functional  

Comments [0]

Nov 28: London Java Unconference

On Sat Nov 28th 2009, I'll be at the London Java Community's Unconference at the IBM south bank building. Not exactly sure what I'll contribute, but my current thinking is something around the area of approaches to adding Scala into existing Java projects.

Check out the details on the Upcoming page or read more on the LJC's blog post. It's £20 to cover costs (any left-over money is put behind the bar :-), but hurry... when I last checked there were only 11 places left out of 50.

Loading mentions Retweet
Filed under  //   events   java   scala  

Comments [0]

Setting the character encoding in Scala

The only reliable way we've found for setting the default character encoding for Scala is to set $JAVA_OPTS before running your application:


$ JAVA_OPTS="-Dfile.encoding=utf8" scala
Welcome to Scala version 2.7.5.final [...]
Type in expressions to have them evaluated.
Type :help for more information.

scala> val x = "garçon"
x: java.lang.String = garçon

Just trying to set scala -Dfile.encoding=utf8 doesn't seem to do it. Of course, you may not need this if your OS defaults to a sensible character encoding. I'm lumbered with something called "MacRoman"...

You'll also want to make sure your terminal is set to UTF-8 encoding, which on the Mac is Terminal -> Preferences -> Settings -> Advanced -> International.

Loading mentions Retweet
Filed under  //   scala  

Comments [0]

The Scala REPL is great for Java developers too

This post is for Java developers who have heard about Scala but, although it might sound interesting, are getting on with what they need to do in Java thankyouverymuch.

If that's you, it's still worth installing Scala because the command-line tool makes noodling with Java a delight. The tool in question is the REPL (read-eval-print-loop, a language shell).

Two quick examples...

Let's say there's some API you're going to use, but you just can't quite remember the format of the return result. The REPL is a great way to quickly find out what you actually get. Here's what I found out looking for the list of all TimeZones:


$ scala
Welcome to Scala version 2.7.5.final [...]
Type in expressions to have them evaluated.
Type :help for more information.

scala> import java.util.TimeZone
import java.util.TimeZone

scala> TimeZone.getAvailableIDs()
res2: Array[java.lang.String] = Array(Etc/GMT+12, Etc/GMT+11,
MIT, Pacific/Apia, Pacific/Midway, Pacific/Niue,
Pacific/Pago_Pago, Pacific/Samoa, US/Samoa, America/Adak,
America/Atka, Etc/GMT+10, HST, Pacific/Fakaofo,
Pacific/Honolulu, Pacific/Johnston, Pacific/Rarotonga,
Pacific/Tahiti, SystemV/HST10, US/Aleutian, US/Hawaii,
Pacific/Marquesas, AST, America/Anchorage, America/Juneau,
A...


Most of the developers I know might do a double take at the results syntax but wouldn't have a problem reading that TimeZone.getAvailabeIDs() gives me back an array of strings like "Pacific/Tahiti". No Scala knowledge required to make use of that tool (ok, I left the line-ending semi-colons out, but you can put them in if you like).

Second example. Quick! Answer this: what does String.split return if there are no matches to the pattern? Not sure? Try it and see:


scala> "Pacific/Tahiti".split("/")
res3: Array[java.lang.String] = Array(Pacific, Tahiti)

scala> "wibble".split("/")
res4: Array[java.lang.String] = Array(wibble)


Hope that's useful. Don't miss that you have command history editing (arrow keys on my keyboard).

If you want to do more take a look at First Steps to Scala.

Loading mentions Retweet
Filed under  //   java   scala  

Comments [0]

Using an existing Scala + Maven project in Eclipse

In case you're having problems using the Scala IDE for Eclipse with Maven projects, here's what I do:

  • Generate the Eclipse project files from the shell: mvn eclipse:eclipse. If you already have Eclipse .project files, you'll have to remove them first or mvn eclipse:clean.
  • In Eclipse, do a File -> Import... and select "General -> Existing Projects into Workspace", navigate to my maven project and select it.
  • This gives you a Scala project, but you'll need to enable Maven: right click on the root of the project in the Package Explorer in Eclipse, select Maven menu and enable.

The plugins I have look like this:

...and it all works very well. The Maven plugin is the m2 one.

Troubleshooting: If that doesn't work first time for you: Project -> Clean... is your friend. If you're still having problems, a Refresh and Close Project followed by an Open project is good. In the worst case, close the project, exit Eclipse, remove the .metadata folder (at your own risk), and restart.

You might also want to check out the Scala IDE for Eclipse wiki pages for how others use Maven.

And for the record, I'm using a Mac (64bit, 10.5.7), with Maven 2.2.0 configured in Eclipse preferences to be an External installation (not the Embedded, but I don't know if that makes a difference or not), JDK 1.5, using Eclipse classic 3.4.2.

Loading mentions Retweet
Filed under  //   eclipse   maven   mvn  

Comments [0]

The Smileys in Scala

or: a visual interpretation of some of the syntax of the Scala programming language, with the aim of providing an aide memoire.

The Happy Walrus     : =>


(Yeah, I needed to include the : to make this work).

"The walrus prefers shallow shelf regions and forages on the sea bottom." And like the walrus, in Scala the symbol for by name parameters allows the shallow surface parameter to forage deep inside your code.

An example from Beginning Scala of a method that keeps appending the results of a block of code until the test is true:


def bmap[T](test: => Boolean)(block: => T): List[T] = {
val ret = new ListBuffer[T]
while (test) ret += block
ret.toList
}

Here we see two walruses, test and block, neither of which are evaluated as parameters until you dive into the body of the method.

The Scissors     >:


Putting a lower bounds on a type is rather like cutting off the option of passing a subclass. That is, anything to the left of the scissors in...

def doStuff[B >: T](p: B) = ...

... is snipped away if the type to the left is a subclass ("below") the type on the right. I find it helps to mentally rotate 90 degrees anti-clockwise to see the scissors cutting B if it's "below" T in the class hierarchy.

Chapter 19 of Programming in Scala has the details, as does 8.3 of Scala By Example (PDF).

Let's wield the scissors, by considering a manager who can't handle detail: they can think about fruit and apples, but nothing more specific...


scala> case class Fruit()
defined class Fruit

scala> case class Apple() extends Fruit
defined class Apple

scala> case class Pippin() extends Apple
defined class Pippin

scala> class Manager[A >: Apple]
defined class Manager

scala> new Manager[Fruit]
res2: Manager[Fruit] = Manager@3b2000a5

scala> new Manager[Apple]
res3: Manager[Apple] = Manager@276c9124

scala> new Manager[Pippin]
:11: error: type arguments [Pippin] do not conform to class
Manager's type parameter bounds [A >: Apple]


The Fussy Bird     <:


When it comes to...

A <: B

...the fussy bird knows that the morsel on the left is the special, tastier class when compared to the big old lump of class to the right. In Scala it signifies an upper bound, that A must be the same or a subtype (specialism) of B. And special means tasty, so no wonder she's got her beak and eyes pointing left towards the tasty class.


scala> case class Stuff()
defined class Stuff

scala> case class Food() extends Stuff
defined class Food

scala> case class TastyFood() extends Food
defined class TastyFood

scala> def peck[A <: Food](p: A) = println("yum")
peck: [A <: Food](A)Unit

scala> peck(Food())
yum

scala> peck(TastyFood())
yum

scala> peck(Stuff())
:10: error: inferred type arguments [Stuff] do not conform
to method peck's type parameter bounds [A <: Food]
peck(Stuff())

The bird is so fussy she'll even be happy with Nothing.

So that's the three I've had to work to remember. I hope I've got that far enough in the direction of correct to be useful. Someone will have to sort out stories for <% (view bounds) and the rest of the syntax you might see such as /:.

Loading mentions Retweet

Comments [0]