background preloader

Scala

Facebook Twitter

After the horse has bolted: Option in Scala vs null in Java. When I first came to Scala a few months ago, one of the things I'd heard was to avoid using null and use the Option class instead.

After the horse has bolted: Option in Scala vs null in Java

Great, I thought. Exploring Lightweight Event Sourcing - DUSE 2011-10-05. Delightful Coding with Scala - Revisited Scala Change History. Scala School. Other Languages: About Scala school started as a series of lectures at Twitter to prepare experienced engineers to be productive Scala programmers.

Scala School

Scala is a relatively new language, but draws on many familiar concepts. Thus, these lectures assumed the audience knew the concepts and showed how to use them in Scala. Is Scala really too complex for average developers? I have been evaluating Scala for quite some time now as an alternative to Java for enterprise development and one of the most common criticisms I have seen against Scala is that it is too complex for average developers.

Is Scala really too complex for average developers?

A quick Google search on Scala Complexity returns numerous links to blogs both defending and criticizing Scala for its perceived complexity. In my opinion one key aspect that has been ignored in this debate is that adoption of a framework/language/whatever in a large enterprise is almost never about technology per say, but has more to do with the culture of the organization. To better understand the statement ‘Scala is too complex for average developers’, we will have to dig a little bit deeper into the prevalent culture in most IT departments in large enterprise today.

This can be done by slightly tweaking the Type XY theories created and developed by Douglas McGregor at MIT in 1960s. Yes, Virginia, Scala is hard - Good Stuff. Let me first say that I am a Scala lover and have been a Scala champion for almost 5 years.

Yes, Virginia, Scala is hard - Good Stuff

I've written books and articles on Scala. I've worked with dozens of companies that have launched Scala and Lift projects. I've code reviewed many dozens of Scala projects. I used to think that Scala was easy. It was, and continues to be, a cure for some of the numerous problems with Java.

Scala Style Guide — Scala Style Guide v1.2.7 documentation. Www.codecommit.com/scala-style-guide.pdf. Roundup: Scala for Java Refugees. 13 Feb 2008 To be honest, I’m somewhat kicking myself for writing this post.

Roundup: Scala for Java Refugees

As I’ve said many times: roundup posts are for people who are too lazy to write real content. I can’t tell you how many blogs I’ve come across which have a roundup-to-post ratio of easily 3:1. You know it’s a bad sign when sites start having roundups of their roundups… Meta-roundups aside, I decided (after much deliberation) that a single post linking to all six parts of the series would be useful to one or two people. Of course it’s always possible that you subscribe to my way of looking at things. Part 1: main(String[]) Mapreduce - Scala analogues of QtConcurrent. Manifests: Reified Types. Reification (n.): When an abstract concept [...] is treated as a concrete 'thing'.[1] When Java-the-language added generic types in version 1.5, Java-the-virtual-machine (JVM) did not.

Manifests: Reified Types

Generic types are a fiction of the compiler. They exist at compile time, but they are omitted from the generated bytecode and are therefore unavailable at run time. This phenomenon is known as erasure. By contrast, when C# added generic types in version 2.0, the .NET Common Language Runtime (CLR) added them as well. Comparing Apples to Pears in Scala - or Abstract Types to the Rescue. Abstract types in Scala can make your life much easier.

Comparing Apples to Pears in Scala - or Abstract Types to the Rescue

In this blog I’m going to recap my intellectual journey to compare 'apples to pears' in a typesafe manner, which led me to abstract types. My quest was to write code, which enables me to compare different kinds of currencies as elegant as possible. Scala’s parallel collections. Scala 2.9 introduced parallel collections, which mirror most of the existing collections with a parallel version.

Scala’s parallel collections

Collections that have been parallelized this way have received a new method called par which magically parallelize certain operations on this collection. For example, here is a sequential version: And the parallel version (notice the extra par keyword): Obviously, the ordering will change each time you run the parallel version. This piqued my curiosity and I decided to dig a bit further, starting with investigating what exactly is happening behind the scenes.

First of all, the parallel collections are based on an article called “A Generic Parallel Collection Framework”, by Martin Odersky, Aleksander Prokopec et al, which I highly recommend. Sadly, this article ended up being the only highlight of my research in this area, because the more I dug into the Scala parallel collections, the more disappointed I became. What features of Java have been dropped in Scala? Despite more complex and less intuitive syntax compared to Java, Scala actually drops several features of Java, sometimes for good, other times providing replacements on the standard library level.

What features of Java have been dropped in Scala?

As you will see soon, Scala isn’t a superset of Java (like Groovy) and actually removes a lot of noise. Below is a catalogue of the missing features. break and continue in loops. Conversions between Java and Scala collections. Like Scala, Java also has a rich collections library.

Conversions between Java and Scala collections

There are many similarities between the two. For instance, both libraries know iterators, iterables, sets, maps, and sequences. But there are also important differences. In particular, the Scala libraries put much more emphasis on immutable collections, and provide many more operations that transform a collection into a new one. Sometimes you might need to pass from one collection framework to the other. To enable these conversions, simply import them from the JavaConversions object: You have now automatic conversions between Scala collections and their corresponding Java collections. Internally, these conversion work by setting up a "wrapper" object that forwards all operations to the underlying collection object. Your experience with Scala+Wicket.

[#SONARPLUGINS-1288] Add integration of Scala as new language in Sonar. Playing with Scala’s pattern matching « Kerflyn's Blog. How many times have you been stuck in your frustration because you were unable to use strings as entries in switch-case statements. Such an ability would be really useful for example to analyze the arguments of your application or to parse a file, or any content of a string. Meanwhile, you have to write a series of if-else-if statements (and this is annoying). Another solution is to use a hash map, where the keys are those strings and values are the associated reified processes, for example a Runnable or a Callable in Java (but this is not really natural, long to develop, and boring too).

If a switch-case statement that accepts strings as entries would be a revolution for you, the Scala’s pattern matching says that this is not enough! Beginning sbt0.10. Level Programming in Scala. This series is intended as a guided tour of some type-level programming I have done in Scala. It generally consists of code and examples with a few lines of explanation. It is usually assumed that the reader understands the features of Scala’s type system. This is not always a good assumption about either the author or the reader of course, so comments and questions are welcome. The series is in 10 parts, with some parts consisting of more than one post each. The present post will serve as a table of contents linking to the rest of the series, so bookmark this page for easy reference. Prior work/reference: All source code is available at Get the source and use sbt console to try things out.

Scala’s type system in 2.8 allows recursion, and infinite recursion at that, as demonstrated in [1,2]. Cheat sheet for scala syntax. Scaladays 2011 - The Ease of Scalaz. Scala Implicits : Type Classes Here I Come. We Recommend These Resources I was having some discussion on type classes in Scala with Daniel on Twitter the other day when I suddenly discovered one of my unfinished posts on the same topic. Not that there's anything new that you will get to know from this rant. But these are some of my thoughts on the value that type class based thinking adds to your design space. I started this post when I published my thoughts on orthogonality in design some time back. Let's start with the GOF Adapter pattern .. the object adapter that uses the highly recommended composition technique to bind abstractions. 1.case class Address(no: Int, street: String, city: String, 2. state: String, zip: String)

A crash course in Scala types » Scalabound. After many years of Java development, discovering Scala’s type system and related features was something of a departure for me. Suffice to say GADT wasn’t my first four letter utterance when learning about pattern matching on types, let alone what, when and how to use variance annotations and generalized type constraints.

To kick things off, here’s a ‘small but powerful‘ few lines of buzzword bingo on the type system: …Scala is a statically, strongly, typed language, with implicit type inference and support for structural and existential types. It also features parameterized types, abstract and phantom types and is capable of implicitly converting between datatypes. These core capabilities are utilized by context and view bounds and complimented by generalized type constraints, to provide powerful compile time contracts. In a word, Ouch ! In the remainder of this post, I’ll try to demystify these concepts and sew the seeds of intrigue for further investigation. And again, Ouch ! House !