Scala Developer’s Level

Martin Odersky wrote the leveling of Scala developers:

Level A1: Beginning application programmer
Java-like statements and expressions: standard operators, method calls, conditionals, loops, try/catch
class, object, def, val, var, import, package
Infix notation for method calls
Simple closures
Collections with map, filter, etc
Level A2: Intermediate application programmer
Pattern matching
Trait composition
Recursion, in particular tail recursion
XML literals
Level A3: Expert application programmer
Folds, i.e. methods such as foldLeft, foldRight
Streams and other lazy data structures
Combinator parsers
Level L1: Junior library designer
Type parameters
Lazy vals
Control abstraction, currying
By-name parameters
Level L2: Senior library designer
Variance annotations
Existential types (e.g., to interface with Java wildcards)
Self type annotations and the cake pattern for dependency injection
Structural types (aka static duck typing)
Defining map/flatmap/withFilter for new kinds of for-expressions
Level L3: Expert library designer
Early initializers
Abstract types
Implicit definitions
Higher-kinded types

I guess I’m not even on A1 level 🙂

Documenting Jersey REST API

Documentation is error-prone. So the best documentation should be the code itself… or automatically generated from the code.

I haven’t found any open source project that can do this so I created one. As I’m currently learning Scala, I decided to write the code with Scala. You can find the code in Bitbucket:

It’s by no mean complete so feel free to fork and add functionalities or ask for improvements.


How To Use

To use the tools, you must define an init-parameter in the Jersey Container. The param-name should be packageName and the param-value should the complete package name where your REST resources are located. Example is as follow:

    <servlet-name>Jersey REST Service</servlet-name>

If you are using Guice and jersey-guice (which I do), you can define init-parameter as follow:

   ImmutableMap.of("packageName", "de.fraunhofer.iais.tat.resource"));

And that’s all! The rest documentation should be available on path /restDoc.

State of Scala IDE on Eclipse

Even thought Scala is now among the trendy programming languages, it still misses a lot before it is considered as one of the major players.

Most Scala programmers are they who are not satisfied with Java, so it’s natural that most of them were before programming with Java. One of the things Java programmers miss from Scala is a robust and functional IDE. Since I’m a big fans of Eclipse, this means Scala IDE for Eclipse. While surely the improvements have introduced to the plugin, there are many things left out.

So what are still missing? This is my list based on several months experience with Scala IDE. If some missing features are missing (duh…), just comment and I’ll try to update the post.

  • No refactoring. I miss refactoring a lot. I still remember the day I find refactoring features on RefactorIT for JBuilder. It’s like the day you saw sun for the first time. And not long after that, I found Eclipse with its build-in refactoring features. Call me lazy programmer, but programmer should be lazy, isn’t it?
  • The content assist takes (almost) forever. Yesterday I found myself restarting Eclipse about five times just because I’m programming with Scala. And I’ve increase the timeout of content assist ten folds.
  • Content Assist doesn’t show (not nearly) all posibilities. When it works, it doesn’t even show nearly all possibilities I want to have. On some cases, it even can’t show a pretty simple completion for a field. As small example: if I write ‘va’, I hope I can get ‘var’ and ‘val’ as the first entries of the completion suggestion.
  • Limited formatting options. Eclipse’s Java Formatter is the best configurable formatter I’ve ever saw. This Scala formatter doesn’t even come near it.
  • No suggestion, not even correction suggestion. I often use Ctrl+1 in Java editor to assign the statement to a variable. Not possible. If you got errors, you got no correction suggestion.
  • No integration to scala documentation. Weird, but the Scala editor can show Javadoc but no Scala documentation is accessible.
  • No auto import. I ended up importing the whole package everytime I need a class.

But yes, I still put a lot of hope woth Scala IDE. It shouldn’t take a lot of time, because the code is in Scala and Scala means productivity, right?

Deployment parameter for REST resource

When you are creating resource in a REST application, it will only be automatically created if you have an empty parameter. The problem is, sometime we need a resource that is configurable, so it can be reused by other applications.

We can solve this problem by defining init parameter in our web.xml like this:


Or if you’re using Guice (and jersey-guice), changing the end of your ServletModule like this:

     ImmutableMap.of("param", "test"));

The parameter can be read by your resource by defining ServletConfig as field and annotate that with @Context. Example:

public class TestResource {
   @Context ServletConfig config;

   @GET public String testMethod() {
      return config.getInitParameter("param");

Fresh look for your Eclipse editor

The default theme of Eclipse is good, but I must admit that with some configuration, Vim can show code better. And this is pretty easy, just go to Google and search for ‘vim color’.

I know from a long time ago that Eclipse allows us to change the color preference of our editor. Hence I never change the default since it is just too much hassle to do that. Not counting that when I reinstall Eclipse, I might have to reconfigure all that stuffs.

So when I found this plugin Eclipse Color Theme, I know I will like the plugin. But God, how I’m still surprised to see the result.

Do you like it? There are even more themes you can download here.

Representation of class in Scala

Seems very simple but can be source of frustration. So, how to represent class in Scala?

In Java, you refer to a class by adding .class at the end of the class name. In Scala, you get the equivalent of that by using classOf[].

An example for referring String class is as follow:


You can read more about Scala Type System here.