Scala

Coda Hale is Yammer's infrastructure architect. Yammer is moving their infrastructure code from Scala to Java. Typesafe's CEO (the company founded by Scala's creators) asked him for his reasons and his email was made public by mistake. Read more here

 

I've worked for 2 years now in on a complex scalable service exposed via web-service created in Scala and my experiense was very different. Here are my thoughts.

 

First, to summarise the main points of the email:

ittayd 30/11/2011 - 19:06

Here is the presentation given at our last event about moving from Java to Scala.

 

The presentation show how Scala can be used instead of Java to get more concise and modular code gaining productivity and maintenance advantages. It use a simple Android application to show the transition. It touches simple Scala features that make us more productive as well as more advanced ones that make our code better.

 

 

 

 Here's the original presentation:

 

ittayd 22/05/2011 - 21:43

Someone asked me today how to write a service so its API can be used from Java. His problem is that he is using Scala's collection classes but it is not possible to use their methods from Java. This is because when using some features of Scala, the encoded method has a name that is not legal in Java (using '$' in particular).

 

For example:

trait API {
  def service: Map[String, String]
}

 

If we call the method 'service' from Java, there's very little we can do with the result.

 

The common wisdom is to create an adapter class that exposes Java consumable classes. Say, create a JavaAPI interface and JavaAPIImpl. This is very tedious and also tends to become very verbose since if another API interface returns our API interface it also requires wrapping so it will return a JavaAPI interface.

 

ittayd 17/05/2011 - 14:09

I just read a comment in reddit where someone explained that Scala's feature that allows "subj.method(obj)" to be written as "subj metohd obj" is for writing DSLs.

 

(Disclaimer: I don't know what were Martin Odersky's exact reasons for adding this feature)

 

For me the primary reason is not DSLs. It is the simple fact that it makes the language more consistent. In Java, you can write 'x + y', but this is allowed only for special types (primitives and string). This is inconsistent. In scala, 'x + y' is allowed for all types.

 

ittayd 20/01/2011 - 13:36

This post is not yet another introduction to Monads. In fact, I hesitated whether to use the term in the title. Eventually I did, so I wouldn’t get comments that the article is in fact about Monads. It is, but not for the reasons most articles are about.

 

I want to discuss the design pattern that they offer. That is inversion of control between values and functions. Usually we think as values being the arguments to functions. But if we switch things around, making functions the argument of values, it can help make some code more concise and clear. It helps to model different code flows than foo(bar(car()))

 

Since I mentioned the word Monad, I need to give some kind of introduction. It is very superficial. I will then follow with some examples.

 

ittayd 03/10/2010 - 10:10

There's a constant discussion about Scala being a complex language. In this post I'll try to show the simple parts of Scala that make coding easier.

 

My favorite article about why Scala is not complex is by Martin Odersky, the father of Scala: http://lamp.epfl.ch/~odersky/blogs/isscalacomplex.html. But there's one problem with it, it appeals to those already in favor of Scala.

 

I think Scala *is* complex. Some due to the functional concepts that are foreign to the Java world, some due to the requirement to work inside the JVM (and CLR). In fact, I was against Scala since 2006, because then I tried to learn it and found the syntax awkward. I recently had to start using it because a client required me to and haven't looked back since.

 

Ok, so now to the actual post, why should you use Scala: because some parts of it make programming easier even for novices:

ittayd 02/09/2010 - 20:33

Sometimes Scala's compiler will infer the type Nothing for a generic type parameter which may cause an error during runtime. I show here a simple way to avoid that.

 

The method follows the strategy in http://github.com/harrah/up/blob/master/Contains.scala (which presents a more generalized way of declaring type parameters which are required or excluded). The strategy is to cause an ambiguity for the compiler when Nothing is used which will cause it to error.

 

First, a use case: Say I want to make working with Maps that contain multiple types a little easier, for example, working with a Map[String, Any]. Insted of a user needing to call map.get(key).asInstanceOf[Option[MyType]] , I want a method like map.getAs[MyType](key). The code:

ittayd 05/08/2010 - 21:59

Have been wondering how to build your application that have both Java and Scala sources with Maven?

Here you can find a tutorial from http://mackaz.de:

Build a mixed Scala 2.8/Java application and Eclipse Settings for this project

liya 08/04/2010 - 09:04

It looks like the recent trend is blogging about scala-complexity. I thought of writing my own view of things.

 

Mixing up complexity and limits

Scala has its limits. Some things cannot be done easily. The thing about Scala is that it makes people believe they can do anything with it, they are then frustrated when they can't. The scala-complexity blog post for example, tries to create a method that will work on collections, Java's strings and Java's arrays. Seamlessly. This is something you wouldn't even dream of doing in Java (Note: it is in fact possible to do it.)

 

ittayd 11/01/2012 - 18:18

This blog entry came to my attention from reading a lambda group post by Ronen Narkis, and this was my reply:

"

Few days ago I twitted this: "ok, i admit. #Scala actually sucks..."

I didn't read the blog yet (I will though) but if I have to sum up what I think about Scala in one short sentence then it would be: "Yet another lab creation". Exactly like the early version of EJB. It's obvious that it isn't a community driven development. It has nothing to do with developer convenience nor pleasure. It feels like it was created for pure academic purpose. I have tons of other stuff to say about Scala but I don't want to wear you guys out...

"

adi 25/12/2011 - 23:48
Syndicate content