Wednesday 26 May 2010

Simple build configuration for Scala 2.8 with Maven

There are plenty of blogs explaining how to run Scala with Maven, but, unfortunately, many of them are out of them, no less the scala-lang website, which I will try to update with this simple recipe.

The good thing about this configuration, is that is tested with both Eclipse and IntelliJ Idea 9.0.2 (open source)




The directory structure remains the same as for java, with the obvious difference:

src/main/scala
src/test/scala

Finally, add your package and test it with a Canary Test




JUnit 4 + Hamcrest matchers seems like a very simple combination that will get the job done without dealing with the binary incompatibility problems of Scala before the final release of 2.8. It seems that jars need to be compiled against the exact version of the compiler or they won't work. I don't yet know enough about this problem, but was significant enough to drive me away of using the most recent versions of ScalaTest and Specs for now. Thus, I'm sticking to
2.8.0.RC1 which seems to work in all IDEs.

At the moment i'm using Intellij Idea 9.0.2, which comes with a pretty good Scala plugin. Eclipse is usually my IDE of choice, but the plugin is in an early stage yet, since doesn't support any refactorings.

Another rather annoying problem was with Hamcrest, which doesn't have the 1.2 version available in Maven Repositories, but it comes with some nice matchers some I recommend you to download it from their website. It seems that the High priority bug to deploy it in Maven Repo Central has been open for... 3 years! I added the 35th request to get it closed :) Otherwise, just switch to 1.1 version, which is available from Maven Central.


Enjoy!

Monday 17 May 2010

Coding the architecture

Today I attended to a free seminar by Simon Brown of Coding the Architecture today at SkillsMatter, London. He delivers a two day day course on Architecture for developers, and gave a  sneak preview, focusing on non functional aspects, and architecture definition. Essentially, how do you go about writing an architecture from scratch. Overall was pretty solid, although he seems to favour RUP as an intermediate between Waterfall and Agile, but I tend to disagree, but I would be interested in hearing the full course to understand his argument.

If you are interested he also wrote a very interesting article on InfoQ... are you an architect? He helps to visualize the many dimensiones of the role, and he emphasizes many social aspects that are usually overlooked, such as how to communicate an architectural principle across the team or teams.

Sunday 16 May 2010

The end of the line

Ever wondered how to move to the start or the end of the line in the terminal in your MacBook? Ctrl+A and Ctrl+E respectively.

It also works on the Scala REPL, where you can quickly evaluate code snippets. Some useful tips here

Even while you surely know, home, end, page up and down are all accessible by combining the Fn + arrow keys.

Another end of the line shortcut is Shift+G in less. To tail that buffer do Shift+F (Ctrl+C to stop).

Enjoy!

Saturday 15 May 2010

Hello Scala World



Simple and concise. The thing to notice here is the keyword object. Scala has the built in concept of a Singleton, which simplifies design. All the static members are to be placed in the object companion, which replaces enums and acts as a default factory for your object. Brilliant!


To do enums, we have several alternatives:



or



Which can be used extensively with case classes.

Thanks to Carte Cole's syntax highlighting tutorial using SyntaxHighlighter

Vim syntax highlighting for Scala

Scala offers the flexibility to execute from command line (scala -e), through its REPL, as a script, or accessing the conventional main class. While REPL can be useful for quick hacks, the script has the advantage that it can be used for good shell scripts. On my Mac OS X Snow Leopard, (although it works on any unix) I configured vim as such:
curl http://lampsvn.epfl.ch/svn-repos/scala/scala-tool-support/trunk/src/vim/syntax/scala.vim -o .vim/syntax/scala.vim

curl http://lampsvn.epfl.ch/svn-repos/scala/scala-tool-support/trunk/src/vim/indent/scala.vim -o .vim/indent/scala.vim

curl http://lampsvn.epfl.ch/svn-repos/scala/scala-tool-support/trunk/src/vim/ftdetect/scala.vim -o .vim/ftdetect/scala.vim
then inside of vim, activate it:
:syntax on
Finally, to enable highlighting by default, add/modify your .vimrc and add the line
:syntax enable
Restart your console and you can now enjoy scala highlighting (although the color theme probably needs tweaking...)

Polyglot programmer

For years, Java has been considered 'the enterprise programming language', only contested by .Net. But since ruby on rails appeared, the development community started asking questions whether Java was the right choice in every case. A movement sparked by Andy Hunt and David Thomas following their book The Pragmatic Programmer led to the concept of Polyglot Programmer. They suggest that developers should 'speak' more than one language, and learn one every year, to stay fit, and adopt different paradigms such as functional programming (Lisp descendants such as Haskell) or the parallelism friendly Erlang.

Each language have pros and cons, but unlike Ruby, a handful of this new languages chose to profit from the large efforts invested on the JVM. It started off with
Groovy, a dynamic language that appealed Java developers due to its compatibility, Jython (Python interpreter), but moved on to JRuby, Scala and finally Clojure.


Scala has the added benefit that is binary compatible with Java, which means that is fully interoperable, and as such able to access its gigantic library.

From this year onwards, my goal is to become proficient in Scala, which I will be using for my dissertation. Stay tuned for more on Scala!