Archive for July, 2008

Agent based simulation with Repast and Groovy

I’ve always been interested in simulation, and in particular with agent based modelling. There’s something very powerful about the concept of building a set of individuals with simple rules and then running through a set of scenarios.

I’ve noticed that the Repast agent simulation toolkit has updated it’s site and also released Repast Simphony 1.1. I’m going to have a play with this over the next few days using Groovy.

As a side note, installing Repast I had the opportunity/motivation to try out Eclipse 3.4 (Ganymede) for Java and Groovy development. The Groovy plugin seems to be at about the same level of functionality as Netbeans (maybe a less mature but then noting it runs on a stable version Eclipse not a development milestone like Netbeans). Java development with Eclipse seems ‘less out of the box’ than Netbeans, which is less friendly for the newcomer.

Monday 28th July 2008 in Blog

How I use Java, Scala and Groovy

Seeing I’ve talked about Java, Scala and Groovy I thought I’d share an idea about how I use them. This isn’t a comparision, a set of recommendation or pros and cons, just the way I place them. And of course they are all the same deep under the hood so you can do anything in any one.

Groovy, http://groovy.codehaus.org

  • Yes: Grails, integration glue, command-line scripts (eg build scripts, data import and transformation)
  • No: Swing, performance code

Java, http://java.sun.com

  • Yes: Swing, backend web services, areas where IDE plugins speed
  • No: Web frontend

Scala, http://scala-lang.org

  • Yes: ‘Backend services’, functional algorithms, multi-processing (lightweight thread and actors)
  • No: Swing, Web front end (not a comment on Lift just thing Grails is too good)

Four days of talking about programming languages, tomorrow I’ll start think about using one of them.

PS. Not entirely happy with this post, as it feels there’s more of a point to make. I might come back and update after a few days of reflection!

Thursday 24th July 2008 in Blog

Trying not to like Scala

I know I like Groovy (because it’s cool), Java (because it works),  Python (because it’s easy to read). My original background was C/C++ and Assembly background (dirty linen aired) and I can appreciate how these languages improvem on the C/C++ (though many people would say that’s not difficult).

Some languages however I just don’t get, for example, VB, Perl, Ruby, Erlang, Lisp, and Lua. I’m wrong I know - these are all widely used, great languages which are expressive, have unique selling points, offer great functionality, libraries and applications. I suppose I ‘just don’t like the look of them’, and I have the same feeling about Scala.

I shouldn’t like Scala, but I do. I’m not keen on the syntax (too many stray colons, <-, etc) mainly as, unlike Groovy, it feels unfamiliar coming from C/C#/Java. However I love the type safety, functional vs imperative mix, actors, Java interoperability and performance. It seems that with Scala you’ve so much flexibility to gain but nothing too loose (after the learning curve).

In case you are wondering, tomorrow won’t be about yet another VM language (YaVML - good name for language?). I probably won’t even mention Netbeans support for such a language - or that you can get Scala support (or improved Groovy/Grails support) if you go for the bleeding edge nightly version.

Monday 21st July 2008 in Blog

Google sites - SharePoint for everyone?

I first found JotSpot a couple of days before the Google acquisition. I was looking for a way of organising informaiton which was more powerful than Google Notebook but simpler than installing my own wiki. Sadly with the Google acquisition came a closed period and I was unable to register - however I did invest my time in a Mediawiki which has been very useful for capturing thoughts.

According to the Wikipedia link above as of 21 May 2008 Google opened up Google Sites outside it’s Google App offering. Today however was the first day I’d noticed it in the Google mail menu.

Having gone down the wiki route for Venesi I didn’t want to use Google apps - ultimately I think there’s a point when you need to own your own information. Email, bookmarks and so on are one thing (even then email feels a bit questionable) but I’m glad I’ve got my own wiki. (Of course I’m under no illusion that Google’s offering are probably more secure and robust than my server and its application).

Still Google sites is excellent for personal/family/group organisation - I don’t think it’s quite customisable enough to be ‘your web page’, nor can elements be plugged in at the moment. I am already using it to help collect and organise ‘private’ information in a

Having been working on SharePoint recently it’s very nice to see Google sites delivering similar to average users in a simple way. Pages can be created, dashboards, lists created and so on. If it could be extended through development (which maybe it can or will be eventually) then the copy would be complete.

The key difference in Microsoft’s vs Google’s approach seems to be that Google is pushing for the one (Google powered) Internet, whereas Microsoft is happy for everyone to have there own (MS powered) Intranet. Microsoft recognises the one internet but their market share is way down in that space. I hope Google recognises that it’s products have a market place behind the firewall - as I’ve love to be deploying Google Sites (v2 with some more features) rather than MS Windows SharePoint Services (already at version 3). Most people probably feel the same about Outlook vs Calander and Gmail.

The only issue at the moment with sites is that it’s very hard to select a site name - they have to be a http://sites.google.com/site/* and you can’t pick a registered Gmail account. That’s a very big limitation. You can use a Google App with your own domain though to solve this problem.

Sunday 20th July 2008 in Blog

Good idea: Java and Groovy with Netbeans 6.5M1

In my previous blog I forgot to mention the most important benefit of Netbeans 6.5 - the ability to seamlessly mix Groovy and Java within the same project (zero developer effort required). Whilst this is a property of Groovy/JVM, Netbeans removes all the hassle of buildscripts, library management, classpaths, ever growing command lines, etc. The support for calling Groovy from Java is excellent - with full code completion (and includes things like automatic getter and setters you don’t need to write in Groovy).

The real win here is that you can write in Groovy and then optimise elements of your project in Java, without needing to do anything other than ‘New Java file’, and then code up the relevant Java class in your project. Whilst people still debate the speed of Java (vs C++) it’s undeniably faster than Groovy.

In the past using Python I’ve come across times where you simply need to move out of Python to improve performance. In Python that’s always been a major investment in developing C modules and  its’ that a real it of pain:

  • C/C++ isn’t as productive as Python  - longer to write, more to worry about, more lines of code (I know, all these are debatable but giving specific examples will prove anything about any language);
  • The need to input from and output to Python API objects makes for ugly C code (at least around the edges);
  • Memory management issues between Python and C (this is well treated in the Python APIbut still something you need to keep in mind);
  • Larger development, deployment and testing workload to ensure cross platform support (obviously C compiles to platform native code).

I pick Python here from familiarity, but this obviously applies to many (most?) other similar languages (and indeed to Java). Thankfully the JVM saves us from that with Groovy/Scala/JRuby/Java etc.

The equal status of Groovy and Java in Netbeans projects is real move from treating dynamic languages as embedded scripting languages (with painful APIs to integrate). Now, I can create an interface and then choose whether a particular implementation in my project would benefit from ’safe compile time static typing’ or ‘groovier concepts’ - sooner or later, I’ll probably also be able to say if it would be easier to program using a functional style in Scala. Also I can still take advantage of the Netbeans IDE support desgined to ease Java development, for example for UI creation in Matisse. In short, you really can mix and match to use the best language for the job at hand.

To try this you just need to download Netbeans 6.5M1 Java SE version, and then through the Tools > Plugins menu to install the Groovy support (under the Available Plugins tab). Depending on your environment you will also need to point Netbeans to your Groovy/Grails installation folders, which you do through Tools > Options > Groovy area. This will also enable the Grails project  in Netbeans.

To start mixing Java and Groovy just create a Java application project, and then create a new Groovy Class or Source file. Done!

Just for good measure - Netbeans also support JRuby, PHP, Javascript, C/C++ and has plugins in development for Python, Scala, and more no doubt!

Sunday 20th July 2008 in Blog

XMPP client for Groovy (and missing IDE)

I restarted playing around with XMPP and Groovy today. Thanks to Groovy’s excellent support for Java getting a quick and dirty XMPP client using Smack is really easy:

import org.jivesoftware.smack.*
import org.jivesoftware.smack.packet.*
import groovy.swing.SwingBuilder
import java.awt.BorderLayout

swing = new SwingBuilder()
chatFrame = swing.frame(
    title: 'XMPP Chat',
    size:[450,450],
    defaultCloseOperation: javax.swing.JFrame.EXIT_ON_CLOSE) {
    actions() {
        action(
            id: 'SendMessageAction',
            closure: {
                chat.sendMessage messageField.text
                chatArea.text += "Me: ${messageField.text}\n"
                messageField.text = ""
            }
        )
    }

    borderLayout()
    chatArea = textArea(editable:false, constraints: BorderLayout.CENTER)
    messageField = textField(action:SendMessageAction, constraints: BorderLayout.SOUTH)
}

loginDialog = swing.dialog(title: "Login", show: true, size:[300,300]) {
    actions() {
        action(
            id: 'LoginAction',
            closure: { createChat() }
       )
    }

    gridLayout(rows:7, cols:2)
    label("Server:")
    server = textField(text:"talk.google.com")
    label("Port:")
    port = textField(text:"5222")
    label("Domain:")
    domain = textField("gmail.com")
    label("Username:")
    username = textField("username")
    label("Password:")
    password = passwordField(text:"")
    label("Chat to:")
    participant = textField("user@gmail.com")
    button(action:LoginAction, text: "Login")
}

def createChat() {
    cfg = new ConnectionConfiguration(server.text, port.text.toInteger(), domain.text)
    connection = new XMPPConnection(cfg)
    connection.connect()
    connection.login(username.text, password.text)
    connection.sendPacket(new Presence(Presence.Type.available))
    name = connection.roster.getEntry(participant.text).name
    chat = connection.getChatManager().createChat(participant.text, { chat, message ->
        chatArea.text += "${name}: ${message.body}\n" } as MessageListener)
    loginDialog.dispose()
    chatFrame.show()
}

loginDialog.show()

For brevity the above is definitely an example (vs an application). I’d suggest anyone looking for a good example of (structuring) a Groovy Swing application takes a look Greet (and use Groovy 1.6 @bindable vs Groovy 1.5 as above).

Developing in the text editor with Groovy back me back to a time long ago when IDE’s where in their infancy. It really does feel painful working with code completion, or Javadocs to hand. I would go as far as to say that a good Java IDE (such as Netbeans) allows developers to be far more productive than the gains you get from Groovy syntax and language feature - particularly if you are an ‘integration developer’ (i.e working on pulling together libraries into a product).

Seeking an IDE I installed Netbeans 6.5M1, together with the Groovy&Grails plugin. Netbeans 6.5 is pre-beta and the the Groovy plugin is probably less mature than that. However it’s usable within the IDE - but don’t expect too many bells and whistles (e.g. advanced code completion).

I did quickly create a similar application in Java (using Netbean GUI builder) and unsurprisingly that took around 10 minutes, and was about 300 lines of (mostly generated) code. The Groovy version is about 50, but took far longer (mainly due to need to continually look up Smack API and needing to run to errors - not just syntax but also Swing builder layout testing).

Saturday 19th July 2008 in Blog

Return to the matrix

Starting with phrase common to my last few entries, it’s been a while since I posted. However I’m now back in a position (i.e. having an usable internet connection) to start posting with some regularity. It’s been a strange few months and I’ve had very little quality time for the site (or indeed much outside of work) nor for the most part access to the site at all! Being busy is a good thing I hear!

Due to a lack of time I’ve not progressed many of my intended projects, so I’ve a period now to decide where to start and what to do next.

Friday 18th July 2008 in Blog