As you may probably already know, the BCN Developers Conferece is being held on November, and its a fantastic occasion to meet other developers... and spread the word.
BCNDevCon chooses the speakers with a voting system, so if you are interested, give your votes to whatever you are willing to assist there. There are 5 papers proposals related to Scala (and you may recognize some names there).
Here you have a list of those papers that are related to Scala (in no particular order), for your kick reference:
A highly concurrent asynchronous system built on Akka and Scala, by Guillermo Ontañón
Writing Hadoop jobs in Scala using Scalding, by Toni Cebrian
Introduction to scala programming language, by Ignasi Marimon-Clos
Play! 2 framework in Scala, by Ignasi Marimon-Clos
Building an HTTP API with the best of Scala and Java, by Jordi Pradel
So if you want more Scala at BCN Dev Con, go vote your favorite papers!
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming
A development environment for #scalabcn Coding Dojos
This is a short post for assistants to the Scala Developers Barcelona Coding Dojo who may need help or advise installing an starting environment.
This is my personally preferred toolset (JetBrains IntelliJ + SBT) but there are other options (like Maven or Eclipse). Feel free to bring your own configuration!
The development environment
Install SBT. Manual installation is recommended.
Edit or create ~/.sbt/plugins/build.sbt and add the following line:
Once to start with and every time you modify your build.sbt after that, run sbt gen-idea to create IntelliJ descriptors form your build.sbt.
The idea here is to follow the DRY tip and have only one definition for the project: SBT. The definition IntelliJ needs (the IntelliJ modules and project files), are therefore automatically generated from the sbt project definition.
Hands on Scala: Writing a REST API with JAX-RS in Scala
New [Barcelona Scala Developers meetup](http://www.meetup.com/Scala-Developers-Barcelona/) on Wednesday 27 of february at [Itnig](http://itnig.net/en/office)! As you may already know, we, the guys behind funció and [agilogy](http://www.agilogy.com), are also the organizers of the [Barcelona Scala Developers meetup](http://www.meetup.com/Scala-Developers-Barcelona/). We recently reached 50 members and it is high time we meet again to talk about Scala, program in Scala and have a Scala beer! In this talk we ([Jordi Pradel](https://twitter.com/agile_jordi) and [Jose Raya](https://twitter.com/_joseraya)) will develop a little application using JAX-RS, the Java standard for developing RESTful applications, in Scala. And we want to develop it live and from scratch. Attendees will be invited to participate by pair programming with us, asking questions, contributing opinions... How will we do it? Well, of course, in a 100% functional style *and* using agile techniques (like Test Driven Development and Behavior Driven Development). After all, we are agilogy + funció and this is our agile functional style. Many, many thanks to the people at [Itnig](http://itnig.net/en), who will be hosting the event at their wonderful office. And thanks to [Moritz](http://www.moritz.com/) for the beers. Didn't I told you? If you are thirsty, you can grab some beers. ## Information: - **Language?** English. - Spanish or Catalan if everybody understands them - **When?** Wednesday, February, 27 - **Timing?** From 19.00h to 20.30h - **Register** at the [Meetup event](http://www.meetup.com/Scala-Developers-Barcelona/events/105165802/) - **Where?** itnig HQ office: - Carrer Àlaba 61, 5è 2a (08005 Barcelona) - http://itnig.net/en/office ## Collaborators:  [Barcelona Scala Developers meetup](http://www.meetup.com/Scala-Developers-Barcelona/)  [funció](http://func.io)  [agilogy](http://www.agilogy.com)  [Itnig](http://itnig.net/en)
Scala REST API with Jetty, Jersey JAX-RS & Jackson
These days I've been studying different alternatives to implement a REST API in Scala. I had used an almost framework-free approach in a previous project, but this time I had some specific requirements in mind: - I want to be able to discover the API using reflection, so that (eventually) an API documentation can be generated automatically. I'm thinking [Swagger](http://swagger.wordnik.com/). - I want to avoid using unmature frameworks. - I want to avoid using frameworks that abuse Scala operators (what I'd call *emoticonic* frameworks with operaturs such as :>:). - I want top Java interoperability. Being able to easily write some methods or resources in the API in plain old Java is interesting, even if I think we won't need to do so. - I want to be able to do Dependency Injection by hand. I would like to avoid adding Guice or Spring to the mix... until they really pay off (if and when they do). - In general, I want the solution to be as simple as possible. I finally came across a combination that may suit (almost all of) my needs: - Scala 2.9.2 - [Jersey 1.2](http://jersey.java.net/) as the [JAX-RS](http://jax-rs-spec.java.net/) implementation - [Jackson 1.9.5](http://wiki.fasterxml.com/JacksonHome) and [Jackson module Scala 1.9.3](http://wiki.fasterxml.com/JacksonModuleScala) for Scala JSON serialization and deserialization - A [Jetty server](http://jetty.codehaus.org/jetty/) 8.1.0-RC5 to run it - Finally, I did some integration tests using [Scalatest](http://www.scalatest.org/) and [Apache HTTPComponents HTTPClient](http://hc.apache.org/httpcomponents-client-ga/index.html) Check it out here: https://bitbucket.org/jordipradel/jersey-scala-example Ok... in fact, I found some glitches: - Jackson Module Scala can't skip fields with value None when serializing to JSON: It creates a JSON field with null value. Interestingly enough, it works perfectly well the other way arround: Not providing a field in a JSON object is correctly deserialized to None if the Scala property is of type Option. - JSON serialization has been not that simple to configure. And there are many things that still need more exploration: - Error handling using exception mappers - Specifically, JSON deserialization error handling so that we can provide infromative messages about what's wrong with the JSON we receive ## Alternatives Some discarded alternatives were: - [Jerkson](https://github.com/codahale/jerkson): Another Jackson base Scala JSON library... now abandoned. - Scala 2.10.0-RC2: That version didn't play well with Jackson. That is: java.lang.NoSuchMethodError: scala.Predef$.augmentString(Ljava/lang/String;)Lscala/collection/immutable/StringOps Some alternatives I didn't try: - [Jacks](https://github.com/wg/jacks) yet another Jackson based Scala JSON library - [Spray](http://spray.io/) whichs seems a nice alternative... althought I'm not sure how easy it would be to discover the api at runtime and to mix Java and Scala. - [Play! framework](http://www.playframework.org/) which seems more oriented towards application development (with its views, DB layer, etc) - [Lift](http://liftweb.net/): It seems to use pattern matching for URL routing, and that seems difficult to discover using introspection, to say the least. - [Blueeyes](https://github.com/jdegoes/blueeyes), [Pinky](https://github.com/pk11/pinky/wiki) and others
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming
You may probably already know about [BDD](http://en.wikipedia.org/wiki/Behavior-driven_development) and [Cucumber](http://cukes.info/). Well, Cucumber allows you to program the steps in your scenario in Ruby... and now in Java and Scala, too. Therefore, I evaluated Cucumber as a BDD solution for an upcoming Scala project. And it did really well, compared to other solutions that were quite more difficult to set up. This post is almost unnecessary. It is that easy. But, just in case you are unsure what versions to use, or how to do it, here you have a quick recipe. If you want the complete picture, check the example project I just created at Bitbucket: https://bitbucket.org/jordipradel/cucumber-scala-example . ## Ingredients - [SBT 0.12.1](http://www.scala-sbt.org/) - [Cucumber SBT plugin 0.7.0](https://github.com/skipoleschris/cucumber-sbt-plugin) - Scala 2.10.0-RC2 - [Scalatest 2.0.M5](http://www.scalatest.org/): Totally optional, use your preferred asserts! ## Directions 1. Add the SBT Cucumber plguin to your project (file project/build.sbt): resolvers += "Templemore Repository" at "http://templemore.co.uk/repo/" addSbtPlugin("templemore" % "sbt-cucumber-plugin" % "0.7.0") 2. Add Scala version, Scalatest dependency and SBT Cucumber plugin default settings to your project (file build.sbt): scalaVersion := "2.10.0-RC2" libraryDependencies += "org.scalatest" % "scalatest_2.10.0-RC2" % "2.0.M5" % "test" seq(cucumberSettings : _*) 3. Create your feature (e.g. a file Multiplication.feature in src/test/resources/bdd): Feature: Multiplication In order to avoid making mistakes As a dummy I want to multiply numbers Scenario: Multiply two variables Given a variable x with value 2 And a variable y with value 3 When I multiply x * y Then I get 6 4. Create a Scala steps definition class (e.g. in src/test/bdd/MultiplicationSteps.scala): package bdd import cucumber.api.scala.{ScalaDsl, EN} import org.scalatest.matchers.ShouldMatchers import scala.collection.mutable.{Map => MutableMap} class MultiplicationSteps extends ScalaDsl with EN with ShouldMatchers { val vars = MutableMap[String,Int]() var result = 0 Given("""^a variable ([a-z]+) with value (\d+)$"""){ (varName:String, value:Int) => vars += varName -> value } When("""^I multiply ([a-z]+) \* ([a-z]+)$"""){ (var1:String, var2:String) => result = vars(var1) * vars(var2) } Then("""^I get (\d+)$"""){ (expectedResult:Int) => assert(result === expectedResult) } } Note you can use your natural language. Simply import another trait instead of EN. Check the bitbucket repo for an example of a scenario written in [catalan](http://en.wikipedia.org/wiki/Catalan_language). 5. Launch or reload your sbt, then run `cucumber` and see the magic happen! And if you forgot to define a step, you'll get a message that will help in defining it. Something like: [info] You can implement missing steps with the snippets below: [info] Given("""^a variable x with value (\d+)$"""){ (arg0:Int) => [info] //// Express the Regexp above with the code you wish you had [info] throw new PendingException() [info] } ## Conclusions There is no excuse to not be using BDD in your Scala projects. Just try it and you'll never go back. Ah! And thanks to skipoleschris, the person behind the Cucumber SBT plugin, for being so helpful in solving a dependency problem I had. P.S. Ok... The style is not precisely functional with those BDD steps having state. Any ideas on this stuff are welcome, of course.
#You Cannot Correctly Represent Change Without Immutability A recent comment in one of our past articles made me remember this excellent article on immutability. A must read.
On page two hundred and sixteen, after talking about algorithms, data structures, recursion, iteration, trees, high-order procedures, scoping, local variables, data abstraction, closures, message-passing, and a plethora of other topics -- after all that, they introduce assignment!
And with that elegant coup-de-grace (which is not the last in this book!), they vanquish the concept that programming is about manipulating state. With that one stroke, they force you to look back on all you had done in the previous pages in a new and enlightened way -- a functional way.
"Uncle" Bob Martin, in ["Why Clojure"](http://thecleancoder.blogspot.com.es/2010/08/why-clojure.html), writing about ["The Structure and Interpretation of Computer Programs"](http://mitpress.mit.edu/sicp/) (and about Functional Programming, LISP and Clojure).
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming
We at funció are shaking the FP scene here in Barcelona. These guys at the local government are calling for startups to come here and make business. I can see a relation.
Hey people out there, Barcelona is indeed awesome.
Are you lean enough? Let's validate the hypothesis: Take some days and come here. Tell me you are coming and/or join our clojure and scala meetup groups. Code, chat, laugh, whatever. And let's have a beer. Or let us show you somewhere to have a real "arròs a la paella" as a reward after a hard FP coding dojo!
This is a nice introduction to scala, akka, play and heroku. I specially liked the first part (the intro to Scala and akka) as it gives a godd overview of the principles and philosophy behind the scala language and its peculiar approach to functional programming, specially targeted to java programmers. It is also a good introduction to functional programming from a pragmatic point of view: Instead of babbling about functors, monads, calculus, etc. it talks about what kind of stuff can be done more easily in a functional style and explains why it is so.
Recently I posted a video of Rich Hickey (@richhickey), the creator of Clojure, talking about simplicity and retweeted a tweet by @planetclojure of an article by Colin Jones: On Obsession, Primitive and Otherwise. Both sources talk about plain data structures and functions that operate on them vs OO classes with methods to work with them. Coming from an OO background, but having been developing in Scala and Clojure for some months now, I felt the discussion quite interesting.
In this post I argue that there is only one difference between classes+methods and data+functions: encapsulation.
Colin compares funcions+data (what he calls primitives) vs classes+methods and tells us they are quite similar. Using his own example, he says those 2 are the same thing semantically speaking:
In fact, they are exactly the same in some languages. The Nice programming language is a functional language for the JVM created from an academic point of view. One of its really appealing parts is how it mixes OO and functions, in a way I prefer over the Scala way, to be frank. In Nice, you implement a method of class Person as a function:
And you can extend any class like this. You don't need the source code of Person to add such a method, since the method is, in fact, a function.
Are there any other differences between methods (in the OO land) and functions? Let's see [1][2]:
Namespacing? OO methods belong to a class. You (usually) can't add methods to a class unless the class is yours. Functions don't.
You can use namespaces for functions. Or you can see functions like they were methods in a Nice way, and namespace them by the first parameter. E.g. You IDE could autocomplete on the first parameter if your language allowed you to write param1.function(param2,...)
You can add functions to whatever namespace you want. Like you can add methods to whatever class you want in some OO languages.
Polymorphism? OO methods are polymorphic on the first argument (self / this / whatever you call it); that's called single dispatch. FP... depend on the language, but you usually have a superset of what OO polymorphism provides.
Nice can dispatch on all of the parameter types, even on argument values [3]
Clojure can dispatch on all of the parameters... using a function you provide (not only by type)
Discoverability? Data structures such as map have methods to enumerate keys, get values, etc. It should be as easy to discover such things in classes... although it usually isn't. In Scala, for example, it is really difficult to discover the attributes of a case class at runtime. This is, nonetheless, an implementation detail. Scala case classes could have a Map like interface to discover their structure at runtime.
Encapsulation? Indeed. In the OO land, you can encapsulate class attributes so that they are only accessible from methods belonging to that class, but you can't (and you usually don't want to) do so in FP land.
So, finally, it all comes to encapsulation. Should we hide our data structures from unknown / yet to be written / third party functions or should we have open data structures? In Nice, you have an example of a functional language that supports encapsulation, but it is the exception to the rule.
I won't discuss about encapsulation here. Listen to Rich, who argues from the point of view of simplicity. And, of course, a (the) quote:
It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures.
[1] I won't talk about dynamic vs static typing, since it doesn't affect the discussion. After all, you have both dynamic and static typed languages in both the OO and FP lands.
[2] I won't talk about immutable data structures vs mutable data structures neither. Let's assume we are only concerned about immutable data structures, which can be implemented as immutable classes in the OO land.
[3] In Nice, you can declare different versions of a method depending on the type, as usual, but also on values:
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming
Do you want to meet fellow scala programmers in Barcelona and code with them? Come with us to the Scala coding dojo.
http://www.meetup.com/Scala-Developers-Barcelona/events/67974682/