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
for-expressions
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
Actors
Combinator parsers
Level L1: Junior library designer
Type parameters
Traits
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
Extractors
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: https://bitbucket.org/enefem/restdoc

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

Screenshot

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>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>
         com.sun.jersey.spi.container.servlet.ServletContainer
    </servlet-class>
    <init-param>
         <param-name>
              com.sun.jersey.config.property.packages
         </param-name>
         <param-value>
              de.fraunhofer.iais.tat.targeting.resources
         </param-value>
		  </init-param>
    <init-param>
         <param-name>packageName</param-name>
         <param-value>
             de.fraunhofer.iais.tat.targeting.resources
         </param-value>
    </init-param>
</servlet>

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

serve("/*").with(GuiceContainer.class,
   ImmutableMap.of("packageName", "de.fraunhofer.iais.tat.resource"));

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

Eclipse 3.7 M5 New and Noteworthy

Here is the new and noteworthy list for the milestone 5 of Eclipse 3.7 (aka Indigo).

The English Language In 24 Accents

This guy is simply amazing!

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?

guava-r08 is here!

Last night, Kevin released the 8th version of Google Guava libraries. For me personally, nothing so exciting in this release. Just nice to have some bugs fixed and some new methods and classes. MinMaxPriorityQueue could be interesting, but I don’t have scenario where to use it right now.

Enjoy it while it lasts!

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:

<servlet>
    <servlet-name>JerseyTest</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param> 
        <param-name>param</param-name> 
        <param-value>test</param-value> 
    </init-param> 
</servlet>

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

serve("/*").with(GuiceContainer.class,
     ImmutableMap.of("param", "test"));

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

@Path("/test")
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:

classOf[String]

You can read more about Scala Type System here.

Google Cloud Print?

Will it be a better solution than AirPrint?

By connecting your printer with the Google Cloud you will be able to print to your printer from any computer or smart phone, regardless of where you are. Just activate the Google Cloud Print connector in Google Chrome and your printer will automatically be available to you from Google Cloud Print enabled web and mobile apps.