New Year starts with Scala

Slowly up to speed

New Year is here, smoke calming down after a couple of nights of excessess with fireworks (and some other stuff too).

I think tonight, the sky will be clear, and the air fresh again.

After lazying around with my family during the Christmas Break, its time to actually work again.

Preparing lecture for  JG.DKs annual conference

I am preparing my lecture for the Danish Java Groups Annual Conference, it will be held at Hindsgavl Castle on my Island (=Funen) in Denmark. The program is here.

My talk will be about a new language – Scala – which is bytecode compactible with Java, and runs smoothly on the JVM. I claim that Scala is going to give us back Object Oriented progamming – without having to do some of the awkward workarounds, that java is forcing us to do.

Out of the host of new languages that run on the JVM, like JRuby, Groovy and Jython – I really think Scala stands out.

What is so special about Scala?

It is a functional language. It is an object oriented language. It is a type strong language – exactly like Java.

It has traits – an ability to add methods to an interface – a language feature that we have been missing since

It is pure and well designed. Invented by Martin Odersky – who designed the Java generics.

Eventually, Java 7 or 8 will be patched with closures, and traits. But those will be patches. I am right now reading a book by Odersky, Spoon and Venners – Programming in Scala – highly recommendable.

Your hello world in Scala

Curious?

Lets try Scala out.

First, lets get the convenient Eclipse plugin (you need Eclipse 3.4 + to make it work) from its update site:

http://www.scala-lang.org/scala-eclipse-plugin

Select New>Scala Project.

This gives you a … Scala project.

Now in the src folder, add a Scala Application (runnable):package application

object HelloWorld extends Application with FirstTrait{
override def main(args: Array[String]) {
println(“Hello, world from Scala!”)
println(“From trait ” + greet(“world”))
for(arg<-args)
print(arg+” “)

println(main(null))
}
}

Make your first trait:package application

trait FirstTrait {

def greet(name:String):String = “Hello “+name

}

Run the application (Run > Scala Application), to see the output:

Hello, world from Scala!
Now – hello from trait Hello world

Thats it – hello world in Scala.

Hello World in Scala

Screenshot from Eclipse: Hello World in Scala

JAOO

I attended JAOO in Århus this year – what a fantastic experience, this conference has a special atmosphere. Denmark is such a small country, you keep meeting old colleauges, classmates, bosses – whatever.
This years buzz was all about functional languages – we finally need to decide what to do with side effects. One possible solution is to have the language give clear, big warning signs.
This is the old semantics vs syntax discussion: Giving clear names, typesafety etc doesn’t help to achieve the big golden dream of (finally!) having reusable software components. What we need to agree is semantics – what does it do, not syntax – how to call it.
I was enchanted by Bill Verner, and his Scala talk, and I am really looking forward to his newcoming Scala book. A typesafe dynamic language that runs on the JVM – I am kind of convinced that this is exactly what we need. To bad the book isn’t coming out before the conference is over – I would have loved a signed copy.
I also enjoyed Michael Nygards talk “Failure comes in flavors” almost without breath – his rant about patterns and antipatterns when time comes to deploying and keeping our applications alive was full of cliff-hangers. Respect. If you ever have a chance to hear this man talk – and if uptime is of any importance to your next web-app – don’t miss him.
I also spent some time discussing lean/agile architecture with James Coplien and his gang. He is promoting DCI – data, contexts, interaction, which is a new paradigm in structuring your applications architecture. James wants us all to move us away from class-oriented programming to true object oriented programming. We spend a couple of hours hanging out, discussing how to translate his example into different programming languages. I myself tried to convince James that you can do it -in Java too. Sitting together, 5 people, around a table, we discovered how we all have been searching for the same answer. Magic of coincidence, or is it the world allready moving in a new direction?