tag:blogger.com,1999:blog-61650716266160796922024-03-05T07:50:35.544+00:00Quantum LeapOn Scala, Functional Programming, Distributed Computing, architecture, DDD, DevOps and building resilient large scale distributed financial systems.Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.comBlogger27125tag:blogger.com,1999:blog-6165071626616079692.post-27024153286158377592015-03-18T00:47:00.002+00:002015-03-18T00:49:33.004+00:00A Brief History of SBTAny developer that wrote more than a few lines of Scala has eventually heard of <a href="http://www.scala-sbt.org/">SBT</a>. SBT is an efficient build tool with lofty <a href="http://www.scala-sbt.org/0.13/docs/Core-Principles.html">functional principles</a>, an uncommon structure, and <a href="http://www.scala-sbt.org/0.13/docs/Older-Changes.html">a long history</a> of <a href="http://www.scala-sbt.org/0.13/docs/Changes.html">updates</a>.
<br />
<h3>
Prehistory</h3>
The Simple Build Tool, as it used to be called, was <a href="http://www.scala-lang.org/old/node/392.html">originally released in 2008</a>. When the first version 0.3.2 was published, code was hosted in the now almost defunct Google Code, and become the de facto tool for another project popular at the time: Lift. The <a href="https://github.com/sbt/sbt/commit/7f92cc5f4c71107c3f9bc03bfe100ecfa445f7fe">first surviving commit after the migration to Github can be found here</a>, belonging to version 0.5.0. SBT offered a way to build Scala applications with a configuration file written in pure Scala, supported subprojects, ScalaTest, Specs and ScalaCheck, and most importantly, managed dependencies via <a href="http://ant.apache.org/ivy/">Apache Ivy</a> and some support for accessing Maven Repos.
<br />
SBT 0.6 / 0.7.x relied on Scala 2.7, but could compile 2.8 and it was incredibly fragile it the relationship with the Scala Compiler. Any version change would require lots of fiddling around to get it to work (as documented <a href="https://code.google.com/p/simple-build-tool/wiki/Setup">here</a>). SBT was achieving fame by being documented in the <a href="https://twitter.github.io/scala_school/sbt.html">Twitter Scala School</a>
<br />
<h3>
Middle Ages</h3>
Migration from 0.7 to 0.10 in 2011 meant that SBT was itself built with Scala 2.8. A large re-organization meant lots of breaking changes, including the move the the .sbt build file configuration, a new Task engine, improved Plugin system, moving to Github, among others.
This structure has been largely preserved since, despite many internal changes.
<br />
From version 0.11, just a few months after the release of 0.10, SBT itself moved to Scala 2.9, dropping support for Scala 2.7, freeing itself from the legacy scala collection API and lots of quirks. It also meant a large overhaul of the settings API, and removing the local Maven repo, and changing resolvers while moving infrastructure to different organization, once more causing pain for existing users.
<br />
<h3>
Modern Times</h3>
The following year, for Scala Days 2012 saw <a href="http://www.scala-sbt.org/0.13/docs/ChangeSummary_0.12.0.html">the release of 0.12</a> (no pun intended?). Some of the benefits included incremental compilation, cross compilation for different scala versions (important to library writers having to support multiple binary versions of Scala), a launcher that was able to launch previous versions, improved documentation and other fixes. It also saw the introduction of the repositories file for global configuration and changes to the plugin structure. Things generally worked better than before, but migration was still a pain. The plugin ecosystem starts to flourish.
<br />
<h3>
Industrial Age</h3>
SBT 0.13 was more a refinement that a revolution like previous iterations. SBT itself moved to Scala 2.10, and took advantage of the many new features available in the language. Tasks benefited from the improved macro support. The new syntax is implemented by making :=, +=, and ++= macros and making these the only required assignment methods. Documentation also vastly improved, thanks in part to better tooling and the progressive migration towards Typesafe. Up to version 0.13.1, Mark Harrah was the lead developer, but he decided to move on, and Josh Suereth became the main committer for SBT, who released 0.13.2 at the beginning of 2014.
<br />
<h3>
Digital Age</h3>
From 0.13.5+ (currently .6, .7 and soon .8), every release in the Tech Previews for SBT 1.0 focused on improving existing functionality but also making SBT generally more usable and faster.
New Typesafe employees Grzegorz Kossakowski (@gkossakowski) and Eugene Yokota made lots of contributions, such as:
<a href="https://typesafe.com/blog/preview-of-upcoming-sbt-10-features-read-about-the-new-plugins">Auto Plugins</a>: A simpler way to write plugins with dependencies between them.
Better Incremental Compiler: Agressively cache and avoid recompiling, speeding up the build, particularly when macros are involved.
<a href="http://www.scala-sbt.org/0.13/docs/Cached-Resolution.html">Cached resolution</a>: an improvement on the previous consolidated resolution <a href="https://github.com/sbt/sbt/issues/413">cache resolutions for multi projects</a>, which greatly helps speeds up update tasks since Ivy will not see dependencies across projects.
<br />
<h3>
So what is SBT?</h3>
SBT is a number of different technologies under a common group. Lets dissect them.
<br />
SBT Launcher: Starts the SBT main process. Internally uses Scala 2.10 to update itself. All files in the project/ directories belong to it. (<a href="http://www.scala-sbt.org/0.13/docs/Launcher-Architecture.html">Launcher Architecture</a>). This is quite possible the weakest link. The Launcher allows you to boot up the SBT Console. Relies on a multitude of shell scripts and configuration files, with quite some room for misconfiguration.
<br />
SBT Builder: The core of SBT, the reactive build tool. Parallel by default (tasks that don’t have any unresolved dependencies left will be run in parallel). SBT uses Apache Ivy for dependency resolution instead of Maven’s Aether.
Recent versions of SBT also do dependency resolution caching(mainly to speed up Ivy queries), and aggressive compiled code caching. Since the Scala compiler has so much work to do, any speed up is greatly beneficial. Multi projects really help here, where the best practice is to actually create the smallest possible projects, and as many as possible. A great feature of SBT is that it works as a graph instead of a pipeline. It can run tests of already compiled projects while compiling others. This can easily max out the CPU because SBT will aggressively run tasks in parallel, using all available Cores.
<br />
<a href="http://www.scala-sbt.org/0.13/docs/Understanding-Recompilation.html">SBT Incremental Compiler</a>. SBT goes to great lengths to avoid recompiling. It tracks source dependencies at the granularity of source files. For each source file, sbt tracks files which depend on it directly. If the <strong>interface</strong> of classes, objects or traits in a file changes, all files dependent on that source must be recompiled. sbt does not instead track dependencies to source code at the granularity of individual output .class files, as one might hope. Doing so would be incorrect, because of some problems with sealed classes. See the documentation for more details.
<br />
<a href="https://github.com/typesafehub/zinc">Zinc</a>: <a href="http://typesafe.com/blog/zinc-and-incremental-compilation">SBT standalone version of the incremental compiler</a>, available for other build tools. Used by the Maven Scala plugin.
<br />
<br />
SBT Server: Went through several faces. Started as FSC (Fast Scala Compiler). It currently runs a Nailgun server which is keeps it running and warm between executions. See how this affected the design of the <a href="http://blog.jetbrains.com/scala/2012/12/28/a-new-way-to-compile/">Scala plugin for Intellij Idea 12 onwards</a>.
<br />
<p>
<a href="https://github.com/sbt/sbt-core-next">SBT Core Next</a>: Set of reusable auto plugins. These new APIs were mostly created to enable sbt server, but they have null or fallback behavior in traditional non-server sbt, so they are safe to use unconditionally.
The key one to note here is:
<strong>BackgroundRunPlugin</strong>: This plugin introduces the concept of background jobs, which are threads or processes which exist in the background (outside of any task execution). Jobs can be managed similar to OS processes
<br />
</p>
<p>
<a href="https://github.com/sbt/sbt-remote-control">sbt-remote-control</a>: Converts sbt from a command line tool into a general backend for any kind of user interface, command line or GUI. See here for more (potentially out of date) information on the <a href="https://github.com/sbt/sbt/wiki/Client-server-split">Client Server split</a>
<br />
<p>
<a href="http://typesafe.com/community/core-tools/activator-and-sbt">Activator</a>: The Typesafe Activator <a href="http://typesafe.com/blog/typesafe-activator-130-released-contains-new-sbt-server-and-ui">is soon becoming the clean face of SBT</a>. Activator is meant to become some kind of REPL/Play Console/Akka Typesafe Console/SBT/Nailgun/FSC/IDE/Kickstarter <a href="http://typesafe.com/blog/typesafe-activator---an-update-and-roadmap-preview">jack-of-all-trades tool</a>. Large changes have been made, particularly to Play Framework, to extract out the Play Console and externalise those services.
<div class="separator" style="clear: both; text-align: center;"><a href="http://downloads.typesafe.com/website/blog-images/activator%20blog%202.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://downloads.typesafe.com/website/blog-images/activator%20blog%202.jpg" /></a></div>
<div class="separator" style="clear: both; text-align: center;"><a href="http://downloads.typesafe.com/website/blog-images/Activator%20blog%205.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://downloads.typesafe.com/website/blog-images/Activator%20blog%205.jpg" /></a></div>
</p>
<br />
<h3>Summary:</h3>
<p>
SBT is now a mature tool, getting ready for a 1.0 release. In its 6 years history it has shaped the user experience of most Scala users. Typesafe is keen to improve SBT, and brand the Activator as the new build UI for the Reactive Platform. SBT is nowadays a very useful build tool, so if you have had some bad experiences in the past, is time to look again.
</p>Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-13841339522718722682012-09-17T02:24:00.000+01:002012-09-17T03:36:55.395+01:00Building Scala apps with Maven and ScalaTestOf the many Scala projects I know (particularly on Github), most rely on <a href="https://github.com/harrah/xsbt">SBT</a> for the build. However, no matter how convenient SBT is, some projects are more easily handled by Maven, even if it is because a lot of the infrastructure require to deploy large projects, is already managed by it.<br />
<br />
I personally prefer SBT, in fact, you can use <a href="https://github.com/fractal/first-scala-step">this project for quick Scala + SBT + IDEs setup</a>. But for the projects I have at work, Maven is used, so I need to have a decent project file.<br />
<br />
But as soon as you start trying to build something, you realise that the build systems in Scala still are in beta stages. The amount of options, poor documentation, and conflicting views certainly doesn't help:<br />
SBT (with all its versions), two Maven plugins, Intellij, the ever changing Scala IDE plugin and at least two main testing frameworks, ScalaTest and Specs. Oh, and don't forget Java / Scala mixed projects. It can certainly alienate a newcomer.<br />
<br />
In particular, the two maven plugins: maven-scala-plugin, a <a href="http://davidb.github.com/scala-maven-plugin/index.html">scala-maven-plugin</a>, have plenty of different posts on how to configure them, most if not all of them at various stages of decay and rot, even though some of this posts are fairly recent. Or what happens a lot of the time, only fragments are posted, usually with old versions referenced.<br />
The project to use should be <a href="https://github.com/sonatype/m2eclipse-scala">m2eclipse-scala</a><br />
Enough with the problems: Here's a simple, complete, and hopefully up to date example (At least at the time of writing):
<br />
Use my github project <a href="https://github.com/fractal/minimal-scala-maven">minimal-scala-maven</a>, to make sure the latest version, otherwise this is also going to decay soon<br />
<br />
<br />
<br />
<script class="brush: xml" type="syntaxhighlighter">
<![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelversion>4.0.0</modelVersion>
<groupid>com.github.fractal</groupId>
<artifactid>scala-pom-build</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Scala Maven build project</name>
<description>Simple project to get Scala / Java mixed projects with Scalatest</description>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<encoding>UTF-8</encoding>
<scala.version>2.9.2</scala.version>
<scala.maven.plugin.version>3.1.0</scala.maven.plugin.version>
</properties>
<dependencies>
<dependency>
<groupid>org.scala-lang</groupId>
<artifactid>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupid>org.scalatest</groupId>
<artifactid>scalatest_${scala.version}</artifactId>
<version>2.0.M4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupid>junit</groupId>
<artifactid>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupid>org.apache.maven.plugins</groupId>
<artifactid>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupid>org.eclipse.m2e</groupId>
<artifactid>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecyclemappingmetadata>
<pluginexecutions>
<pluginexecution>
<pluginexecutionfilter>
<groupid>net.alchim31.maven</groupId>
<artifactid>scala-maven-plugin</artifactId>
<versionrange>[0.1,)</versionRange>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</pluginExecutionFilter>
<action>
<configurator>
<id>org.maven.ide.eclipse.scala</id>
</configurator>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupid>net.alchim31.maven</groupId>
<artifactid>scala-maven-plugin</artifactId>
<version>${scala.maven.plugin.version}</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
]]>
</script>
It's using ScalaTest 2.0.M4 although is not a requirement. ScalaTest is going to be the an umbrella framework, capable of plugging other testing frameworks on top if need be. A Scala IDE plugin is well advanced too, so quite important. Beware, <a href="http://scalatest.org/user_guide/using_the_scalatest_maven_plugin">scalatest is supposed to provide a new maven plugin</a>, so stay tuned.<br />
<br />
This project should work well with latest 11.1.3 version of Intellij or Scala IDE 2.1 M2 (even tough the maven plugin will complain about lifecycle execution, compiles fine). This last bit I've managed to remove in the past, but I gave up trying to fix every issue. It requires Maven 3.<br />
<br />
See some posts for <a href="http://tysonhamilton.com/2012/04/07/intellij-maven-scalatest/">other working approaches with older plugins</a><br />
<br />
Let me know if it works for you, and you have any suggestions on improvement, in particular around Scala IDE.Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com2tag:blogger.com,1999:blog-6165071626616079692.post-11983216542654663272012-04-28T12:48:00.002+01:002012-04-29T00:15:46.855+01:00The JVM finally moving forward<div>After almost a year of delay, Java 7 has been officially released for the Mac. See<a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">Java 7 Mac OS X download</a> and <a href="http://www.oracle.com/technetwork/java/javase/downloads/jdk-for-mac-readme-1564562.html">README</a>. </div>
<div>In order to use it in Eclipse and others, bear in mind that the PATH is now:
<blockquote>/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents</blockquote>
This may be inaccesible to Eclipse, but you can paste the whole line, or create a symlink. It contains the sources, but no Javadocs.</div>
<div>This is a huge milestone, which marks the beginning of the end for Java 6, which was released 6 years ago. Technologies like Scala have soared since. But now with JDK 7 been readily available in all platforms, and with many bugfixes since the original release, it's time to upgrade. Last step will be JDK7u6 when the JRE will be fully availabe. See my previous post on <a href="http://quantleap.blogspot.com/2012/04/java-7-8-and-beyond.html">Java 7, 8 and beyond</a></div>
<div>Update: After running a couple of scripts, I ran into this issue with <a href="http://webcache.googleusercontent.com/search?q=cache:7T1LwYKfdSMJ:java.net/jira/browse/MACOSX_PORT-564+&cd=1&hl=en&ct=clnk&gl=au">UnknownHostException in JDK7</a></div>
<div>See this snippet:
<script class="brush: java" type="syntaxhighlighter">
<![CDATA[
import java.net.InetAddress;
public class InetAddressTest {
public static void main( String... args ) throws Exception {
System.out.println( "InetAddress.getLocalHost() = " + InetAddress.getLocalHost() );
}
}
]]>
</script><br />
<script class="brush: java" type="syntaxhighlighter">
<![CDATA[
Exception in thread "main" java.net.UnknownHostException: ice: ice: nodename nor servname provided, or not known
at java.net.InetAddress.getLocalHost(InetAddress.java:1438)
at InetAddressTest.main(InetAddressTest.java:5)
Caused by: java.net.UnknownHostException: ice: nodename nor servname provided, or not known
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:866)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1258)
at java.net.InetAddress.getLocalHost(InetAddress.java:1434)
... 1 more
]]>
</script><br />
This is my /etc/hosts
<blockquote>
127.0.0.1 localhost <br/>
255.255.255.255 broadcasthost <br/>
::1 localhost <br/>
fe80::1%lo0 localhost <br/>
192.168.1.3 loki <br/>
</blockquote>
</div>Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0London, UK51.5081289 -0.12800551.350006900000004 -0.443862 51.6662509 0.187852tag:blogger.com,1999:blog-6165071626616079692.post-56605649153207828002012-04-13T22:23:00.004+01:002012-04-29T00:01:39.199+01:00Java 7, 8 and BeyondJava 7 update 4 developer preview is available to download from OpenJDK website. Why is this any important? because is the first candidate release of the official JDK released by Oracle since Apple decided to stop shipping a custom build.<br />
<br />
This also paves the way for further releases of Java 7 and ultimately Java 8 given the imminent end of life of Java 6.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogs.oracle.com/javaone/resource/java_keynote/slide_15_full_size.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="502" src="https://blogs.oracle.com/javaone/resource/java_keynote/slide_15_full_size.gif" width="893" /></a></div><br />
Are you using Java 7 already? I can see it been similar to Java 5. Few people actually using it, and instead moving directly to Java 8, or feel pushed by it, to move into the last known stable version (in this case, 7). <br />
<br />
Java 8 will bring lots of new features making the language a lot closer to what Scala delivers today, and is been heavily influenced by its success. See <a href="http://www.infoq.com/presentations/To-Java-SE-8-and-Beyond">Simon Ritter</a>'s <a href="http://www.slideshare.net/JAX_London/keynote-to-java-se-8-and-beyond-simon-ritter">presentation</a> and <a href="http://www.slideshare.net/JAX_London/java-core-concurrency-in-the-java-language-and-platform-fredrik-ohrstrom">Fredrik Ohrstrom</a> for more details. Better still... get yourself a <a href="http://jdk8.java.net/download.html">build</a> !<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://code.google.com/p/openjdk-osx-build/"><img border="0" height="243" src="http://openjdk-osx-build.googlecode.com/files/JavaPrefs-v5.png" width="320" /></a></div><br />
See <a href="http://jcp.org/aboutJava/communityprocess/edr/jsr335/index.html">Early Draft of Project Lambda by Brian Goetz</a>. More info on <a href="http://openjdk.java.net/projects/lambda/">Project Lambda for Java 8</a>
<div>More updates on Lambda, this time is on collections: <a href="http://cr.openjdk.java.net/~briangoetz/lambda/collections-overview.html">Brian Goetz update on Streams for Java 8</a>. I particularly like to stress this point on his blog post:
<blockquote> we will pursue an evolutionary strategy of adding extension methods to existing interfaces (such as Collection, List, or Iterable), or perhaps to new interfaces (such as 'Stream') that are retrofitted onto existing classes, enabling many of the desired idioms without making people trade in their trusty ArrayLists and HashMaps. (This is not to say that Java will never have a new Collections framework; clearly there are limitations with the existing Collections framework beyond simply not being designed for lambdas. Creating a new-and-improved collections framework is a fine candidate for consideration in a future version of the JDK.)</blockquote></div>
<div>Even with Java8, Scala will continue to be ahead of Java, offering a more powerful and complete solution. The large change that was moving from Scala 2.7 to 2.8 in terms of upgrading collections, will have to wait at least until Java 9 to take effect. Because of this, Scala is a technology to stay, and lead the way to a functional revolution.</div>Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-320732086300341772012-04-13T19:54:00.002+01:002012-04-13T23:23:36.774+01:00Good Days to be Scala developerNext week is <a href="http://days2012.scala-lang.org/">Scala Days London 2012</a>, a 2 days marathon with some elite hackers. It's the first time I'm attending and really looking forward to it. The topics on discussion are <a href="http://days2012.scala-lang.org/node/92">extremely exciting</a>. Distributed and cloud computing, functional theory, Akka, Play Framework, Spark, Finagle, and obviously, cool production scenarios and war stories.<br />
<br />
Typesafe Stack 2.0 brought so many cool things that takes a lot of time just to catchup, so really interested to attend talks around Akka 2.0 and Play 2.0.<br />
<br />
The emphasis that Typesafe and the community are putting on tool support is paying dividends.<br />
<br />
SBT has finally become a stable build environment and the community is thriving with an <a href="https://github.com/harrah/xsbt/wiki/sbt-0.10-plugins-list">ever growing list of plugins</a>. Intellij IDEA support is great and<a href="http://blog.jetbrains.com/scala/"> keeps expanding</a>.<br />
<br />
Today Scala 2.9.2 was released together with Scala IDE 2.1 M1, which pack lots of nice features like <a href="http://scala-ide.org/blog/release-notes-2.1-Milestone-1.html">move refactoring, implicates highlighting, scala debugger and more!</a>. And<a href="http://scala-ide.org/docs/dev/roadmap.html"> the roadmap to the final release</a> looks great. This shows how Scala itself has matured, and how the whole ecosystem is taking life on its own.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://scala-ide.org/docs/_images/example.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="451" width="640" src="http://scala-ide.org/docs/_images/example.png" /></a></div><br />
<br />
<br />
That provides a lot of confidence not just to developers, but to small and large companies, that are increasingly considering Scala, as evidenced by <a href="http://www.itjobswatch.co.uk/jobs/uk/scala.do">the growing number of quality scala jobs available</a>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=scala&l=uk" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="145" src="http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=scala&l=uk" width="320" /></a></div><br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://www.itjobswatch.co.uk/charts/salary-trend.aspx?s=scala&l=uk" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="160" src="http://www.itjobswatch.co.uk/charts/salary-trend.aspx?s=scala&l=uk" width="320" /></a></div><br />
Exciting Scala Days !!Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-3525188884395690072011-12-11T19:29:00.001+00:002012-04-13T22:44:01.167+01:00Understanding the JVM, concurrency and GCA great collection of links and presentations on Java Virtual Machine and why understanding how it works is critical.<br />
<br />
First, let's start with <a href="http://java.sun.com/products/hotspot/whitepaper.html">HotSpot</a>, the default JVM. This is a mandatory intro into the responsibilities of the VM. Next, learning about the some of the most common optimizations that the JIT compiler has available, <a href="http://www.oracle.com/technetwork/java/hotspotfaq-138619.html">HotSpot FAQs</a>, and <a href="http://java.sun.com/developer/technicalArticles/Networking/HotSpot/inlining.html">method inlining</a><br />
<br />
Now we are going to go down one abstraction layer, and jump into the hardware. A great presentation by Jevgeni Kabanov, by far the simplest to undestand: <a href="http://www.infoq.com/presentations/Do-You-Really-Get-Memory">Do you really get Memory?</a> I find this presentation a must see before jumping into the more hardcore versions that follow. In this talk, Jevgeni presents a simplified Java CPU model, showing the CPU, Memory, and more fundamentally, Caches.<br />
<br />
Armed with this knowledge, we are then ready to take on the mammoth paper "<a href="http://www.akkadia.org/drepper/cpumemory.pdf">What every programmer should know about memory</a> by Ulrich Drepper. This is very low level at times, so worth watching <a href="http://www.infoq.com/presentations/click-crash-course-modern-hardware">Cliff Click's presentation: A Crash Course on Modern Hardware</a>, which summarises it nicely.<br />
<br />
Interesting article also on<a href="http://www.infoq.com/articles/memory_barriers_jvm_concurrency"> Memory Barriers</a> and obviously, it wouldn't be complete without <a href="http://techylib.com/view/alex/concurrent_programming_in_java">Doug Lea's concurrency in Java presentation</a>. Always a good read, although really extensive, the <a href="http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html">Java Language Specification, Third Edition</a><br />
<br />
Finally, I have reserved it for the last, <a href="http://www.infoq.com/presentations/Understanding-Java-Garbage-Collection">Gil Tene's excellent Understanding Java Garbage Collection</a>. Brings in lots of points that i didn't know about in my previous post <a href="http://quantleap.blogspot.com/2011/10/art-of-gc-tuning.html">The Art of GC Tuning</a>. In particular, I really enjoyed the discussion around Application Memory Wall, and how our applications seem to range between 1-4 GBs, but rarely take advantage of increasing hardware power, and what are the main problems behind it. He shows how the Azul Zing VM can easily cope with 1/2 TB VMs without pausing.<br />
<br />
That's quite a lot for now!Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-55761538864337831072011-12-03T09:01:00.000+00:002011-12-03T09:01:21.892+00:00Rename a GIT project in GitHubIt is now supported to rename projects in GitHub.<br />
<br />
Go to project admin, and rename.<br />
<br />
Then, in your local .git project, simple edit your '.git/config' file<br />
<br />
<br />
<blockquote>[remote "origin"]<br />
url = g...@github.com:fractal/old-name.git<br />
fetch = +refs/heads/*:refs/remotes/origin/*<br />
...</blockquote><br />
<div>Now just change old-name to new name, save and push</div>Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com1tag:blogger.com,1999:blog-6165071626616079692.post-35567137064460400442011-12-03T08:54:00.001+00:002012-04-13T22:59:02.703+01:00First Scala Step - Simple SBT templateI've created a simple project to clone when you need to get up and running really quickly using the latest Scala tools.<br />
<br />
It provides:<br />
<br />
<ul><li> Scala 2.9.1</li>
<li> SBT 0.11.2</li>
<li> Specs2 1.6</li>
<li> Mockito 1.8.5</li>
<li> Eclipse</li>
<li> IntelliJ IDEA</li>
</ul><div>Clone <a href="https://github.com/fractal/first-scala-step">first-scala-step</a> and start using it! </div><div><br />
</div><div>Alternatively, just today, coolscala has also pushed a similar project to kickstart using Akka 1.3-RC1+ ScalaTests : <a href="https://github.com/coolscala/startakka">start-akka</a></div><div><br />
</div><div><br />
</div>Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-33942460009693844942011-11-06T17:14:00.010+00:002011-11-25T00:14:01.981+00:00Exploring Scala Collections<div>This weekend I've been trying to write some microbenchmarks and discovered a large differences between different implements of the same problem: create a list of 10 million objects and print only the ones that are modulo of a million.</div><br />
<div>This is the code in question. It runs in 141 milliseconds requiring no more than 27 mbs JVM (the smallest i could create). <br />
</div><br />
<script class="brush: scala" type="syntaxhighlighter">
<![CDATA[
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeUnit._
object LightAndFast extends App {
def chrono[A](f: => A, timeUnit: TimeUnit = MILLISECONDS): (A,Long) = {
val start = System.nanoTime()
val result: A = f
val end = System.nanoTime()
(result, timeUnit.convert(end-start, NANOSECONDS))
}
def millions(): List[Int] = (0 to 10000000).filter(_ % 1000000 == 0).toList
val results = chrono(millions())
results._1.foreach(x => println ("x: " + x))
println("Time: " + results._2);
}
]]>
</script><br />
<br />
<div>As shown in this StackOverFlow question, a range followed by a filter operation can even beat the performance of an array of primitives in Java. The space required is smaller, and the amount of time to execute it is barely comparable, whereas any other approach was in between one and two orders of magnitude worse, depending the case.</div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrWsekselY2tHyE32yIPitFc1nmQeZNYZ5HphO3Z_Ucj5pV7ldiZLrWxtTwzVcn0HAFhBzfvBQsUVwGRwA1Iw9LZAnSquQvhipBhHr599WSoi0XtFE8df0wFFynQwu-Z2MnHdeUvzr0Eeu/s1600/large+collections+performance+chart.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="174" width="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrWsekselY2tHyE32yIPitFc1nmQeZNYZ5HphO3Z_Ucj5pV7ldiZLrWxtTwzVcn0HAFhBzfvBQsUVwGRwA1Iw9LZAnSquQvhipBhHr599WSoi0XtFE8df0wFFynQwu-Z2MnHdeUvzr0Eeu/s320/large+collections+performance+chart.png" /></a></div><br />
<div>I learnt several things with this simple exercise, from Ranges, Array (compile to primitives, no need for Wrappers), and performance monitoring.</div>Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0Westminster, London, UK51.5001524 -0.1262361999999939151.322796399999994 -0.39052969999999393 51.6775084 0.1380573000000061tag:blogger.com,1999:blog-6165071626616079692.post-65482366621129970972011-10-23T12:34:00.004+01:002011-11-06T17:34:53.935+00:00The costs of concurrency and the actor model<div>I was interested to understand more about <a href="http://www.defmacro.org/ramblings/concurrency.html">how actors are implemented in Erlang</a>. In an old but still relevant article, an argument is raised: <blockquote>These days every third grader knows that processes are expensive. Ok, so we're not using real processes, we're using threads, but if you constantly create, destroy, and switch between thousands of threads you'll bring any system to a crawl. Threads are expensive for a number of reasons. They take a long time and a lot of memory to create because the operating system needs to set up many things (the stack, internal data structures, etc.) for them to work. They take a long time to destroy because all the resources they consumed need to be freed. And they take a long time to switch between because unloading registers, storing them, loading them back, and flipping the stacks is complicated business.</blockquote>So how expensive it really is to create a Thread in java these days? </div><div><a href="http://vanillajava.blogspot.com/">Peter Lawrey, writer of the excellent Vanilla Java blog</a>, tell us that roughly, <a href="http://stackoverflow.com/questions/5483047/why-is-creating-a-thread-said- to-be-expensive">creating a Thread takes<br />
about 70μ (microseconds)</a>, which is fairly expensive, but not prohibitive. The size of the stack can be configured by command line argument to the JVM, with a default of 512kb. According to some Mac OS X 10.5 docs, a thread takes about 90μ, which is kind of validates his results. </div><br />
<div>As it was pointed out in the StackOverflow discussion<br />
<blockquote>Creating threads is expensive if you're planning on firing 2000 threads per second, every second of your runtime. The JVM is not designed to handle that. If you'll have a couple of stable workers that won't be fired and killed over and over, relax.</blockquote>This is slightly different in Erlang, where everything is a Process, so the model leads you to that situation. </div><br />
<div>Essentially, Erlang uses a kind of lightweight processes, akin to green threads (VM scheduled pseudo-threads as opposed to real threads). Since they only consist of a mailbox implemented as a queue, it takes about 300 words to build one, meaning we can create thousands, even millions of them, so the only constrain is memory.</div><br />
<div dir="ltr" style="text-align: left;" trbidi="on">I read a great post on <a
href="http://www.unlimitednovelty.com/2011/07/trouble-with-erlang-or-erlang-is- ghetto.html">Erlang lightweight-process actor concurrency and it's inherent problems in terms of message passing costs</a>, i.e., having to serialize the entire message between processes, even within the same node. The lack of zero-copy messaging between actors, even within the same node, can really hurt performance. It also talks a great deal on how the BEAM VM and HiPE JIT compiler aren't anywhere near as good as the industry leader JVM (or his favoured Azul Systems "pauseless" VM). </div><br />
<div>On that basis, after years of hardcore work on Erlang, he decants for Erjang (using Java's Killim actors) or Clojure, possibly<br />
due to been more functional and lisp syntax. I wonder why Scala wasn't mentioned? <a href="http://akka.io">Akka</a><br />
offers the same principles of Erlang actors, but implemented in a much more robust way and running on top of the JVM.<br />
</div><br />
<div>Scala actors, particularly Akka actors, use configurableexecutors that efficiently reuse threads (and in Akka 2.0, this will be declaratively configured). Thus, i can see Akka<br />
as supersiding Erlang, an the heir of the throne in actors concurrency. </div>Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-33983898832742060192011-10-22T11:18:00.005+01:002011-11-25T00:01:45.421+00:00The art of GC Tuning<div dir="ltr" style="text-align: left;" trbidi="on">Great presentation discussing <a href="http://www.scribd.com/doc/37127094/GCTuningPresentationFISL10">best practices when tuning Garbage Collection on the JVM</a><br />
<br />
The different GC Collectors:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://blog.dynatrace.com/wp-content/GC-Compare.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="140" src="http://blog.dynatrace.com/wp-content/GC-Compare.png" width="320" /></a></div><br />
Fragmented Heap:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://blog.dynatrace.com/wp-content/compact-600x343.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="182" src="http://blog.dynatrace.com/wp-content/compact-600x343.png" width="320" /></a></div><br />
<div>See <a href="http://www.oracle.com/technetwork/java/example-141412.html">JVM GC tuning docs here</a></div><br />
Also, <a href="http://blog.dynatrace.com/2011/05/11/how-garbage-collection-differs-in-the-three-big-jvms/">a comparison of all the JVM GC implementations</a> (particularly valuable given that Java8 will incorporate JRockit's features.<br />
<br />
I've came across this links by reading the blog post on the new features of Cassandra 1.0. Some<a href="http://www.datastax.com/dev/blog/whats-new-in-cassandra-1-0-performance"> very interesting JVM tuning</a> allowed them to increase performance manyfolds.</div><br />
<br />
<div>The JVM JIT compiler at runtime, and even the java and particularly scala compiler at compile time, <a href="http://www.stanford.edu/class/cs343/resources/java-hotspot.pdf">love small methods that can be analysed in isolation</a>. It is very important to consider the effect that the compiler can have whenever reading microbenchmarks.</div><br />
<div><a href="http://java.sun.com/developer/technicalArticles/Interviews/goetz_qa.html">Quoting Brian Goetz</a>: <br />
<br />
<blockquote>"Often, the way to write fast code in Java applications is to write dumb code -- code that is straightforward, clean, and follows the most obvious object-oriented principles."<br />
Brian Goetz<br />
Technology Evangelist, Sun Microsystems</blockquote></div><br />
<div>For <a href="https://github.com/HugeCollections/Collections">huge collections, is better to use a framework that can handle billions of items</a>, potentially mapped outside of the heap, thus avoiding Full GC completely.</div>Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-11478295550288307382011-10-21T19:07:00.002+01:002011-10-22T09:51:59.786+01:00Scala Options: Type and Null Safety<div dir="ltr" style="text-align: left;" trbidi="on"><div>Options are great because they allow you to circumvent the <a href="http://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare">$1 billion bug (Hoare)</a>. </div><div>Several posts discuss the great values of Options. It was Graham Tackley who really made me click when he presented <a href="http://blog.tackley.net/2010/09/option-in-scala-vs-null-in-java.html">Options as collections with zero or one elements in it.</a></div><div>Yesterday I was trying to make good use of this idea, and came with the problem of how retain only the elements that actually contain a value. Since you cannot call get on a None for obvious reasons, there must be an easy way to retrieve only the values.</div><div>Here's what i found:</div><br />
<script class="brush: scala" type="syntaxhighlighter">
<![CDATA[
scala> val x = Some("x")
x: Some[java.lang.String] = Some(x)
scala> val y = Some("y")
y: Some[java.lang.String] = Some(y)
scala> val z = Some("z")
z: Some[java.lang.String] = Some(z)
scala> val items = List(x,y,z)
items: List[Some[java.lang.String]] = List(Some(x), Some(y), Some(z))
scala> val moreItems = None :: items
moreItems: List[Option[java.lang.String]] = List(None, Some(x), Some(y), Some(z))
scala> val valuesOnly = moreItems.flatMap(_.toList)
valuesOnly: List[java.lang.String] = List(x, y, z)
]]>
</script><br />
<br />
<div>I've transformed a List[Option[String]] with possible Nones in it, to a List[String].</div></div><br />
How about this then?<br />
<script class="brush: scala" type="syntaxhighlighter">
<![CDATA[
scala> val so1 = List(Some(1), None, Some(2), None, Some(3))
so1: List[Option[Int]] = List(Some(1), None, Some(2), None, Some(3))
scala> so1.flatten
res0: List[Int] = List(1, 2, 3)
]]>
</script><br />
<br />
<div>Which is basically doing the operation that I've just done before, call flatMap(_.toList)</div><br />
<div>This makes passing around options a really valuable thing, because you have safety in your operations with minimal effort.</div><br />
<a href="http://blog.tmorris.net/scalaoption-cheat-sheet/">Very useful Scala Option cheatlist by Tony Morris</a>Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-7793475354908851142011-10-07T23:21:00.000+01:002011-10-07T23:21:22.924+01:00Supporting different paradigms of Parallelism<div dir="ltr" style="text-align: left;" trbidi="on">Doug Lea's keynote in Scala Days is a really interesting <a href="http://days2011.scala-lang.org/node/138/274">presentation</a>.<br />
<br />
It shows the importance of multicore, Amdahl's Law and lots more. Well worth it.</div>Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-40179749488223082062011-09-26T00:05:00.004+01:002011-10-07T23:57:49.606+01:00Attending the Low latency summit conference in London<div dir="ltr" style="text-align: left;" trbidi="on">I will be attending the Low-Latency Summit 2011 - Winning Strategies for Deploying Low-Latency Technologies. I expect to get a good insight on vendor technologies used for ultra low latency such as Infiniband networks. <br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://www.a-teamgroup.com/insightevents/2011/nyc-wsll/" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="75" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-EYSamE_N964j4MaS4LjDOljFC-zIsghVrtWBxvrzposcFn7ZkxR-dhCl9jfgbjys3wJfX9mfNkOrmtxJfHISgRs5_d1c9CH2MA9s5I_tj3qIU_GmeoY4KUC9Wf7V1ClkK72GgVgiebIL/s320/Low-latency+summit+2011.png" width="320" /></a></div><br />
Thanks <a href="http://algorithmsinaction.blogspot.com/">Eleanna</a> for the invite!<br />
<br />
</div><div><strong>Update:</strong> Some interesting panels during the event. The low-latency website is probably one of the best takeaways from here. Here's a good summary on <a href="http://low-latency.com/article/101-what-latency">classification of sources of latency</a> and suggestions on how to mitigate them.<br />
<br />
Also available is this <a href="http://low-latency.com/sites/default/files/session_4_-_pre-lunch_keynote_-_leveraging_low_latency_for_global_exchange_leadership.mp3">podcast from NASDAQ OMX’s Bjorn Carlson</a> discussed technologies and approaches that are in use today at markets around the world. <br />
</div>Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-20279882362925844142010-11-13T17:02:00.006+00:002011-11-06T17:35:51.159+00:00Building Scala applications with SBT + IdeaIntellij IDEA is a great tool for Scala Developers. A couple of days ago I attended a great event of the London Scala User Group where, Richard Hallaway, Phill Wills and Maciej did a <a href="http://richard.dallaway.com/intro-to-the-simple-build-tool-at-lsug">very good intro to this tool</a>. This guide explains how to quickly leverage a couple of tools to setup a new Scala project in minutes.<br />
<div><br />
First of all, start downloading right now the <a href="http://confluence.jetbrains.net/display/IDEADEV/IDEA+X+EAP">latest build of Idea X community edition</a> for your platform, this will probably be ready by the time we finish with the setup. You'll also need the Scala and SBT plugin.<br />
<br />
<div>There are basically two ways to setup your idea projects with SBT. The first would be using <a href="http://heikoseeberger.blogspot.com/2010/08/how-to-setup-scala-project-with-sbt-and.html">Heiko Seerbergers guide</a> to setup the project from Idea. I prefer to do it the way that Mikko Peltonen suggests... <a href="https://github.com/mpeltonen/sbt-idea">SBT-Idea.</a><br />
<br />
</div><div>First, you'll need the great <a href="http://code.google.com/p/simple-build-tool/">SBT (Simple Build Tool),</a> which is a build tool written in Scala and for Scala. Its power lies in that it relies on convention over configuration and giving you full control over your builds. No longer long XML configurations + Shell scripts. SBT can do everything from one single script. Furthermore, builds can pickup only the changes you made, and recompile and run only those tests. Check it out!</div><div><br />
</div><div>After you <a href="http://code.google.com/p/simple-build-tool/wiki/Setup">setup SBT </a> , create a new project:</div><div><br />
</div><div>sbt</div><div>Name: <project name=""></project></div><div>Organization: <group id=""></group></div><div>Scala: 2.8.1</div><div>sbt: 0.7.4</div><div><br />
</div><div>this will create most of your project.</div><div><br />
</div><div>then exit the console, go to project folder, and create a folder build and inside, a scala file such as this:</div><div><br />
</div><div><br />
<script class="brush: scala" type="syntaxhighlighter">
<![CDATA[
import sbt._
class MinesweeperProjectt(info: ProjectInfo) extends DefaultProject(info) {
// Dependencies
val scalatest = "org.scalatest" % "scalatest" % "1.2" % "test" withSources
val junit = "junit" % "junit" % "4.8.1" % "test"
}
]]>
</script><br />
<br />
<br />
Go back to the sbt console, type update, and it will pull the dependencies.<br />
<br />
Use the <a href="http://code.google.com/p/simple-build-tool/wiki/Processors">SBT processor</a> as specified <a href="https://github.com/mpeltonen/sbt-idea">here</a>:<br />
<br />
<span class="Apple-style-span" style="font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 13px; line-height: 18px;"></span><br />
<pre style="background-color: rgb(248, 248, 255) !important; border-bottom-color: rgb(222, 222, 222) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; border-left-color: rgb(222, 222, 222) !important; border-left-style: solid !important; border-left-width: 1px !important; border-right-color: rgb(222, 222, 222) !important; border-right-style: solid !important; border-right-width: 1px !important; border-top-color: rgb(222, 222, 222) !important; border-top-style: solid !important; border-top-width: 1px !important; color: rgb(68, 68, 68) !important; font-size: 12px !important; font: normal normal normal 12px/normal Monaco, 'Courier New', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace; line-height: 1.5em !important; margin-bottom: 1em !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 1em !important; overflow-x: auto !important; overflow-y: auto !important; padding-bottom: 0.5em !important; padding-left: 0.5em !important; padding-right: 0.5em !important; padding-top: 0.5em !important;">> *sbtIdeaRepo at http://mpeltonen.github.com/maven/
> *idea is com.github.mpeltonen sbt-idea-processor 0.1-SNAPSHOT
...
> update
...
> idea
...</pre><br />
this will create your project. Now, import in IDEA. All your SBT structure will be recognized.<br />
<br />
Now let's setup the FSC (Scala Fast Compiler Server). SBT is great for quick reloads, but i still prefer to have fast compilation within the IDE.<br />
<br />
For that, just go to Edit Configurations in your run targets in the toolbar, and create a new Scala Compilation Server using the following details. I had issues in the past when ticking the box shared configurations but it probably has been fixed already.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiy8E5p4UoAoKrdMUGLd0UcsTo3DSVqId2mJ9krTLwy660UshGhrJdN-4tf-E-EraE5POfj5z5Odm2Zw3dNMREEsZsY-mycThyphenhyphenFgOpnPc5HReuZj_q6OY5Sz5VEZmaISVsJgcNthvlRRy5/s1600/fsc.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="123" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiy8E5p4UoAoKrdMUGLd0UcsTo3DSVqId2mJ9krTLwy660UshGhrJdN-4tf-E-EraE5POfj5z5Odm2Zw3dNMREEsZsY-mycThyphenhyphenFgOpnPc5HReuZj_q6OY5Sz5VEZmaISVsJgcNthvlRRy5/s320/fsc.png" width="320" /></a></div><br />
<div>That's all you need ! Super fast compilation within Idea. And remember if you run your commands in sbt with a tilde ~ they will automatically run every time you switch back to the sbt console and it detects a file change.</div><br />
<div>Finally, don't forget your .gitignore</div><br />
<pre>.idea/
lib_managed/
project/boot/
project/build/target/
target/
</pre></div></div>Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com2tag:blogger.com,1999:blog-6165071626616079692.post-42514458184424920502010-11-13T16:28:00.001+00:002010-11-13T16:32:36.692+00:00Scala 2.8.1 releasedPlenty of <a href="http://www.scala-lang.org/node/8102">bug fixes</a> (more than 100 in 3 months!). Great to see a very active community, kicking the tires and gathering to solve problems. Furthermore, It's fully binary compatible with 2.8, which means no need to match library versions as it happened with the RCs for 2.8. Also, the <a href="http://www.scala-lang.org/api/current/index.html">improvements to Scaladocs</a> make it look very snappy<br />
<br />
All in all, we can see the the Scala language growing at a fast pace. Many new books are coming, including Phillip Haller's <a href="http://www.artima.com/shop/actors_in_scala">Actors in Scala</a> and three others by Manning "in Action" series. Browse the <a href="http://www.scala-lang.org/node/959">complete list of books</a> if you are interested.Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-60342683046560857382010-10-31T17:18:00.001+00:002011-11-06T17:35:35.603+00:00Scala just pushed Play in web developmentUntil recently, Scala only had Lift has a successful web framework. Meanwhile, the ruby gang has hundreds of them, more importantly ruby on rails, Sinatra and others. But things are changing fast in the scala world. While <a href="http://www.scalatra.org/">scalatra</a> deals with Sinatra, there was nothing quite like ror. Enter <a href="http://www.playframework.org/">Play Framework</a> for <a href="http://www.scala-lang.org/">Scala</a>. <a href="http://www.playframework.org/modules/scala">Module history here</a><br />
<br />
I must admit that <a href="http://www.playframework.org/documentation/1.1-trunk/guide1">this 11 pages guide to build from scratch an entire blog system</a>, together with captcha, user administration console, open id authentication, using a clean RESTful interface, together with autogenerated unit, integration and selenium tests.... well, this is just absolutely fantastic. That's what i call a quality framework documentation! Scala just pushed Play > !<br />
<br />
If you add f<a href="http://www.zeroturnaround.com/blog/free-javarebel-for-scala-users-zeroturnaround-announces/">ree JRebel free licenses to Scala developers</a> by ZeroTurnaround, Scala is automatically an ultra productive environment for web development!<br />
<br />
Great effort! Can't wait for Play Framework 1.1!Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-1996183479048870042010-10-13T23:26:00.002+01:002011-11-06T17:35:15.574+00:00Scala community growing ever fasterI'm becoming more involved with the Scala community and it looks very, very promising. The Scala Lift-Off event in London was a success, as demonstrated by <a href="http://richard.dallaway.com/scala-lift-off-london-was-wonderful">richard's blog</a> and maciek's notes on <a href="http://www.mmakowski.com/wiki/tech:scala_lift_off_london_2010_day_1">day 1 </a> and <a href="http://www.mmakowski.com/wiki/tech:scala_lift_off_london_2010_day_2">day 2</a><br />
<br />
Scala 2.8 was released in July, and already has an impressive list of bugfixes in 2.8.1. This demostrates the commitment from the community. Furthermore, Martin Odersky announced Scala Solutions, a new venture to offer commercial support and training.<br />
<br />
The two biggest proposals of the event were Lift, which released the version 2.1 of their framework. <a href="http://www.manning.com/perrett/">Tim, who is writing a book on Lift</a> made some really interesting comments. Particularly, I learnt about <a href="http://squeryl.org/">Squeryl</a>, a fantastic framework to construct SQL queries in a friendly Scala DSL syntax, offering full compiler support ... and more importantly, refactoring.<br />
<br />
Akka, the concurrency framework is close to the much awaited 1.0 release. Jonas Boner has made many presentations since then, including <a href="http://sna-projects.com/blog/2010/10/akka/">one at LinkedIn</a> , which, by the way, uses Scala intensively with both <a href="http://sna-projects.com/norbert">Norbert</a> and <a href="http://www.scalatra.org/">Scalatra, a Sinatra-like web framework in Scala</a><br />
<br />
Graham Tackley, and ex-colleague of mine, did a nice presentation on The Guardian <a href="http://www.slideshare.net/tackers/java-to-scala">move to (and love of) Scala</a><br />
<br />
Videos are available <a href="http://skillsmatter.com/event/scala/scala-lift-off-london-2010">here</a><br />
<br />
For great presentations, including some upcoming features in 2.9, have a look at the <a href="http://days2010.scala-lang.org/node/136">Scala Days 2010</a> website. Parallel collections, scala refactorings for Eclipse, and much more.<br />
<br />
Exciting days for the Scala community !<br />
<br />
In the meantime, the demand for Scala in my current job is growing exponentially, so I'm currently preparing some presentations on the subject. Stay tuned!Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-16277453313607959362010-10-13T22:55:00.002+01:002010-10-13T23:03:03.088+01:00King Java 7 is Dead, long live King Java 7!FInally, after <s>months</s> years of <a href="http://blogs.sun.com/mr/entry/rethinking_jdk7">discussions</a>, Java 7 finally has a certain release date. Fortunately, <a href="http://blogs.sun.com/mr/entry/plan_b_details">Plan B</a> won, which means that all the available features are going to be shipped soon (mid 2011), and all the nice-to-have's including Project Lambda are delayed until Java 8, in late 2012.<br />
<span class="Apple-style-span" style="font-size: 11px;"><br />
</span><br />
This is great news for a community left in dire needs for an upgrade after almost 6 years (by the time of the release), and a half version (Java 6 update 10) which was shipped under the covers with many features pressing to be released.<br />
<span class="Apple-style-span" style="font-family: 'Lucida Grande'; font-size: small;"><span class="Apple-style-span" style="font-size: 11px;"><br />
</span></span><br />
This has huge implications for the Scala community, which can deliver today what Java would only be able to offer in 2013, while improving day by day thanks to the JVM 7. I can foresee a JVM increasingly more detached from the Java language itself, and Scala becoming a new powerful and widely accepted language.<br />
<br />
<br />
Modular Java? with OSGI 4.2 available, why bother waiting?<br />
<br />
<br />
Furthermore, IBM just announced that will be <a href="http://www.jroller.com/scolebourne/entry/no_java_7_the_end">joining OpenJDK</a>, ending years of dispute with the aborted Apache Harmony JDK.<br />
<br />
<br />
So, good news for the JVM ecosystem.Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-88796903235075673682010-07-14T19:45:00.000+01:002010-07-14T19:45:21.687+01:00Scala 2.8.0 FINAL releasedThe long awaited Scala 2.8.0 has been released today (just in time for my dissertation!)<br />
<br />
The list of new features is gigantic, and thoroughly deserves a 3.0 release, but due to distribution issues, the version upgrade is just minor. <br />
<br />
Most distinguished changes, the complete revamp of the collections API, named and default arguments, package objects, enhanced event based actors better documentation, thousands of bug fixes, Scala Eclipse IDE... too many to enumerate! Detailed <a href="http://www.scala-lang.org/node/7009">changeset</a> in the Scala website.<br />
<br />
But most significantly, it means that all the scala libraries can now be compiled against a stable version, due to binary incompatibility even across minor releases.<br />
<br />
This is a great day for the growing Scala community!Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-58594248795597683652010-06-06T14:51:00.003+01:002010-06-06T15:06:12.422+01:00Comparing functional programming with JDK7 Lambdas and ScalaIt seems that since Oracle bought Sun, they want to start breathing new life into Java. Out of the blue, Project Lambda seems to be pushing the spec for what would end up been functional idioms for Java.<br />
<br />
The debate that the new syntax brings is captured in t<a href="http://www.infoq.com/news/2010/06/lambda-syntax-debate">his InfoQ article on project Lambda</a>.<br />
<br />
compare Java 7's:<br />
<script class="brush: scala" type="syntaxhighlighter">
<![CDATA[
@Test
def testJava7Lambda(){
int incremented = #(int x)( x + 1 ).(3);
assertTrue(4 == incremented);
}
]]>
</script><br />
<br />
with Scala's<br />
<br />
<script class="brush: scala" type="syntaxhighlighter">
<![CDATA[
@Test
def testScalaLambda(){
def increment = (x: Int) => x + 1
assertThat(increment(3), is(4))
}
]]>
</script><br />
<br />
<br />
for my part, i prefer Scala's functional syntax, since I have a first class function that i can invoke. Brian Goetz (Concurrency guru) suggests that at the moment they are focusing in functionality rather than syntax, and that it will evolve. <br />
<br />
Now, they better work a lot in order to improve this spaghetti:<br />
<br />
<script class="brush: scala" type="syntaxhighlighter">
<![CDATA[
int i4 = #(Number x)(x.intValue()).(new Float(3.0f));
assertTrue(3 == i4);
]]>
</script><br />
<br />
For a move in depth review of the changes proposed, read <a href="http://www.infoq.com/articles/lambdas-java-analysis">this analysis on Project Lambda</a> in InfoQ <br />
<br />
The interesting point to make out of this is that Functional Programming is becoming more and more important and Java doesn't want to miss out. A few months ago, JDK7 was leaving closures out of the spec in order to ship a highly demanded final version. But now Oracle is in command, and they want to include FP in Java. This means that effectively Functional Programming is now becoming mainstream, supported in almost every major platform: F# in .Net, Scala, python, javascript, groovy, and now Java.Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-52033316611478230442010-05-26T20:34:00.006+01:002010-06-06T18:39:01.704+01:00Simple build configuration for Scala 2.8 with Maven<div>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.</div><br />
The good thing about this configuration, is that is tested with both Eclipse and IntelliJ Idea 9.0.2 (open source)<br />
<br />
<script class="brush: xml" type="syntaxhighlighter">
<![CDATA[
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelversion>4.0.0</modelVersion>
<groupid>maven-scala-test</groupId>
<artifactid>maven-scala-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<repositories>
<repository>
<id>scala-tools.org releases</id>
<name>Scala-tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
<releases><enabled>true</enabled></releases>
</repository>
<repository>
<id>scala-tools.org snapshots</id>
<name>Scala-tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-snapshots</url>
<snapshots>
<enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginrepositories>
<pluginrepository>
<id>scala-tools.org</id>
<name>Scala-tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupid>org.scala-lang</groupId>
<artifactid>scala-library</artifactId>
<version>2.8.0.RC1</version>
</dependency>
<dependency>
<groupid>org.scala-lang</groupId>
<artifactid>scala-compiler</artifactId>
<version>2.8.0.RC1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupid>junit</groupId>
<artifactid>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupid>org.hamcrest</groupId>
<artifactid>hamcrest-all</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<sourcedirectory>src/main/scala</sourceDirectory>
<testsourcedirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<artifactid>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<optimize>true</optimize>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupid>org.scala-tools</groupId>
<artifactid>maven-scala-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java-version>1.6</java-version>
</properties>
</project>
]]>
</script><br />
<br />
<br />
The directory structure remains the same as for java, with the obvious difference:<br />
<br />
src/main/scala<br />
src/test/scala<br />
<br />
Finally, add your package and test it with a Canary Test<br />
<br />
<script class="brush: scala" type="syntaxhighlighter">
<![CDATA[
package test
import org.junit.Test
import org.junit.Assert.assertThat
import org.hamcrest.CoreMatchers.is
class CanaryTest {
@Test
def testTrue(){
assertThat(true, is(true))
}
@Test
def testFalse(){
assertThat(false, is(false))
}
}
]]>
</script><br />
<br />
<br />
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 <br />
2.8.0.RC1 which seems to work in all IDEs.<br />
<br />
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.<br />
<br />
Another rather annoying problem was with <a href="http://code.google.com/p/hamcrest">Hamcrest</a>, 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.<br />
<br />
<br />
Enjoy!Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-33560173224641603642010-05-17T23:25:00.000+01:002010-05-17T23:25:43.433+01:00Coding the architectureToday 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 <a href="http://www.infoq.com/articles/brown-are-you-a-software-architect">sneak preview</a>, 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.<br />
<br />
If you are interested he also wrote a very interesting article on InfoQ... <a href="http://www.infoq.com/articles/brown-are-you-a-software-architect">are you an architect?</a> 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.Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-2140570685177962532010-05-16T19:48:00.004+01:002010-05-17T22:56:34.052+01:00The end of the line<div style="margin: 0px;">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.</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;">It also works on the Scala <a href="http://en.wikipedia.org/wiki/Read-eval-print_loop">REPL</a>, where you can quickly evaluate code snippets. Some useful tips <a href="http://blog.xebia.com/2009/07/19/scala-repl-tips-and-tricks-trunk-only/">here</a></div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;">Even while you surely know, home, end, page up and down are all accessible by combining the Fn + arrow keys.</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;">Another end of the line shortcut is Shift+G in less. To tail that buffer do Shift+F (Ctrl+C to stop).</div><div style="margin: 0px;"><br />
</div><div style="margin: 0px;">Enjoy!</div>Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0tag:blogger.com,1999:blog-6165071626616079692.post-36012507427475289832010-05-15T19:12:00.007+01:002010-05-17T23:09:31.895+01:00Hello Scala World<script class="brush: scala" type="syntaxhighlighter">
<![CDATA[
object HelloWorld {
def main(args: Array[String]) = println("Hello Scala World!")
}
]]>
</script><br />
<br />
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 <i>companion, </i>which replaces enums and acts as a default factory for your object. Brilliant!<br />
<br />
<br />
To do enums, we have several alternatives:<br />
<br />
<script class="brush: scala" type="syntaxhighlighter">
<![CDATA[
object Color extends Enumeration("red", "green", "blue") {
type Color = Value
val RED, GREEN, BLUE = Value
}
]]>
</script><br />
<br />
or<br />
<br />
<script class="brush: scala" type="syntaxhighlighter">
<![CDATA[
object Color extends Enumeration {
val RED = Value("Red")
val GREEN = Value("Green")
val BLUE = Value("Blue")
}
]]>
</script><br />
<br />
Which can be used extensively with case classes.<br />
<br />
Thanks to Carte Cole's <a href="http://blog.cartercole.com/2009/10/awesome-syntax-highlighting-made-easy.html" title="code to do quick syntax highlighting">syntax highlighting tutorial</a> using <a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter">SyntaxHighlighter</a>Anonymoushttp://www.blogger.com/profile/16919807495582849009noreply@blogger.com0