background preloader

Scala

Facebook Twitter

Example of currying in scala. A Tour of Scala: Currying. ProGuard. Why Scala? Before answering the question of "Why Scala? ", we first need to answer the question "what is Scala? " From the Scala website, the following overview can be found: Scala is a modern multi-paradigm programming language designed to express common programming patterns in a concise, elegant, and type-safe way.

It smoothly integrates features of object-oriented and functional languages. Scala is object-oriented: Scala is a pure object-oriented language in the sense that every value is an object. Types and behavior of objects are described by classes and traits. Class abstractions are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance. For some developers, these incentives will be enough to lure you away from Java into the Scala world.

So, once again, "why Scala? " Many programmers love Ruby, they just can’t get enough of it. Continuing on, Ian notes that: Scala's far from perfect. Roundup: Scala for Java Refugees. 13 Feb 2008 To be honest, I’m somewhat kicking myself for writing this post. 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.

So if you like to save things with del.icio.us or even plain-old-bookmarks (POBMs for short), this is the one! And if no one finds it useful, eh, I suppose Google probably likes it. Of course it’s always possible that you subscribe to my way of looking at things. Part 1: main(String[]) Introductory article giving motivation for learning Scala and some first steps to “get your feet wet” in the language. Part 2: Basic OOP Looking at Scala’s syntax in a little more detail. Part 3: Methods and Statics. First Steps to Scala. ScalazineFirst Steps to Scalaby Bill Venners, Martin Odersky, and Lex SpoonMay 9, 2007 Summary In this article, you'll follow twelve steps that are designed to help you understand and gain some basic skills in the Scala programming language.

Scala is a statically typed, object-oriented programming language that blends imperative and functional programming styles. Scala is designed to integrate easily with applications that run on modern virtual machines, primarily the Java virtual machine (JVM). The main Scala compiler, scalac, generates Java class files that can be run on the JVM. However, another Scala compiler exists that generates binaries that can be run on the .NET CLR, as Scala is designed to integrate with both the Java and .NET worlds.

In the Java world, the Scala language can be used alongside the Java language—either as an alternative to Java—to build applications that run on the JVM. Scala was developed starting in 2003 by Martin Odersky's group at EPFL, Lausanne, Switzerland.

REPL

A Taste of 2.8: The Interactive Interpreter (REPL) The Scala Interpreter (often called a REPL for Read-Evaluate-Print Loop) sits in an unusual design space - an interactive interpreter for a statically typed language straddles two worlds which historically have been distinct. In version 2.8 the REPL further exploits the unique possibilities. Package and Class Completion On startup, the REPL analyzes your classpath and creates a database of every visible package and path.

This is available via tab-completion analagous to the path-completion available in most shells. If you type a partial path, tab will complete as far as it can and show you your options if there is more than one. scala> scala.co<tab> collection compat concurrent scala> org.w3c.dom.DOMI<tab> DOMImplementation DOMImplementationList DOMImplementationSourcescala> org.w3c.dom.DOMImplementation Member Completion Both static and instance methods of objects are also available.

Interactive Debugging Coming Soon, Scala 2.8. Scala 2.8 Collections API. September 7, 2010 In the eyes of many, the new collections framework is the most significant change in Scala 2.8. Scala had collections before (and in fact the new framework is largely compatible with them). But it's only 2.8 that provides a common, uniform, and all-encompassing framework for collection types.

Even though the additions to collections are subtle at first glance, the changes they can provoke in your programming style can be profound. In fact, quite often it's as if you work on a higher-level with the basic building blocks of a program being whole collections instead of their elements. Easy to use: A small vocabulary of 20-50 methods is enough to solve most collection problems in a couple of operations.

Concise: You can achieve with a single word what used to take one or several loops. Safe: This one has to be experienced to sink in. Fast: Collection operations are tuned and optimized in the libraries. Universal: Example: Next: Scala array operations. Scala - User - FreeBSD problem (2.8-RC6) Scala 2.8 Collections API -- Arrays. Array is a special kind of collection in Scala. On the one hand, Scala arrays correspond one-to-one to Java arrays. That is, a Scala array Array[Int] is represented as a Java int[], an Array[Double] is represented as a Java double[] and a Array[String] is represented as a Java String[].

But at the same time, Scala arrays offer much more than their Java analogues. First, Scala arrays can be generic. That is, you can have an Array[T], where T is a type parameter or abstract type. Second, Scala arrays are compatible with Scala sequences - you can pass an Array[T] where a Seq[T] is required. Given that Scala arrays are represented just like Java arrays, how can these additional features be supported in Scala? The Scala 2.8 design is much simpler. The interaction above demonstrates that arrays are compatible with sequences, because there's an implicit conversion from arrays to WrappedArrays. There is yet another implicit conversion that gets applied to arrays. Next: Strings. The busy Java developer's guide to Scala: Collection types.

For the Java™ developer learning Scala, objects provide a natural and easy point of entry. Over the past several articles in this series, I've introduced you to some of the ways that object-oriented programming in Scala really isn't much different from Java programming. I've also shown you how Scala revisits traditional object-oriented concepts, finds them wanting, and reinvents them for the 21st century. Something important has been lurking behind the curtain all this time, however, waiting to emerge: Scala is also a functional language. (Functional, I say, as opposed to all those other dysfunctional languages.)

Scala's functional orientation is worth exploring, and not only because you've run out of objects to play with. Functional programming in Scala will give you some new design constructs and ideas, as well as built-in constructs that make programming certain scenarios (such as concurrency) much, much easier. Each of these types offers a new way to think about writing code. Scala Collections for the Easily Bored Part 2: One at a Time. 28 Jul 2008 As I hinted previously, this series is intended to delve into Scala’s extensive collections API and the many ways in which it can make your life easier. Probably the most important operations you could ever perform on collections are those which examine each element, one at a time. After all, what’s a more common array idiom than looping over all values? In that vein, this article starts by looking at foreach, the imperative programmer’s bread-and-butter when it comes to types like Array and List.

But rather than just stopping there, we also will look at more powerful, higher-order operations like fold, map and the ever-mysterious: flatMap. Iterating As I said above, looping over every item in a collection is probably the most heavily used operation in a programmer’s repertoire. This code should be old hat to anyone coming from a Java background. The same approach is taken in Scala. Here we define an anonymous method (Scala’s name for a closure) which takes a single parameter. Scala Standard Library 2.9.0.1 - _root_ Scala by Example. Zero to Sixty: Introducing Scala - Programming Scala.

Akka Project. Typesafe. The Scala Programming Language.