background preloader

Scala School

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 is a relatively new language, but draws on many familiar concepts. Approach We think it makes the most sense to approach teaching Scala not as if it were an improved Java but instead as a new language. Most of the lessons require no software other than a Scala REPL. Also You can learn more elsewhere:

mongodb/casbah - GitHub Effective Scala Table of Contents Other languages 日本語Русский简体中文 Introduction Scala is one of the main application programming languages used at Twitter. Scala provides many tools that enable succinct expression. Above all, program in Scala. This is not an introduction to Scala; we assume the reader is familiar with the language. This is a living document that will change to reflect our current “best practices,” but its core ideas are unlikely to change: Always favor readability; write generic code but not at the expensive of clarity; take advantage of simple language features that afford great power but avoid the esoteric ones (especially in the type system). And have fun. Formatting The specifics of code formatting — so long as they are practical — are of little consequence. This is of particular importance to Scala, as its grammar has a high degree of overlap. We adhere to the Scala style guide plus the following rules. Whitespace Indent by two spaces. Naming Use short names for small scopes Use vals Prefer:

Programming in Scala, First Edition Programming in Scala, First Editionby Martin Odersky, Lex Spoon, and Bill VennersDecember 10, 2008 Martin Odersky made a huge impact on the Java world with his design of the Pizza language. Although Pizza itself never became popular, it demonstrated that object-oriented and functional language features, when combined with skill and taste, form a natural and powerful combination. Pizza's design became the basis for generics in Java, and Martin's GJ (Generic Java) compiler was Sun Microsystem's standard compiler starting in 1.3 (though with generics disabled). Since that time, we at Sun tried to simplify program development by extending the language with piecemeal solutions to particular problems, like the for-each loop, enums, and autoboxing. Lately, there has been a backlash against statically typed languages. Scala is a tastefully typed language: it is statically typed, but explicit types appear in just the right places. Will Scala be the next great language? Who should read this book

Learn Getting Started Install Scala on your computer and start writing some Scala code! Dive straight into the API. Tutorials Digest bite-size pieces of the essentials. Online Learning There are a few interactive resources for trying out Scala, to get a look and feel of the language: Functional Programming Principles in Scala, free on Coursera. Books There are more and more books being published about Scala. Bleeding Edge If you are interested in finding out about the hottest, most pressing issues of tomorrow in the Scala world, have a look at the Scala Improvement Process (SIP) page. Older Documentation The documentation below may be a bit outdated, but provides insights into the (historical) design principles of the language : Brief Scala Tutorial: a 20 page introduction to scala and some of the basic concepts and a good place to start.

Circumflex — the exquisite flavor of Scala development Programming in Scala, First Edition Programming in Scala, First Editionby Martin Odersky, Lex Spoon, and Bill VennersDecember 10, 2008 Martin Odersky made a huge impact on the Java world with his design of the Pizza language. Although Pizza itself never became popular, it demonstrated that object-oriented and functional language features, when combined with skill and taste, form a natural and powerful combination. Pizza's design became the basis for generics in Java, and Martin's GJ (Generic Java) compiler was Sun Microsystem's standard compiler starting in 1.3 (though with generics disabled). I had the pleasure of maintaining this compiler for a number of years, so I can report from first-hand experience that Martin's skill in language design extends to language implementation. Since that time, we at Sun tried to simplify program development by extending the language with piecemeal solutions to particular problems, like the for-each loop, enums, and autoboxing. Will Scala be the next great language? How to use this book

10 Scala One Liners to Impress Your Friends - @sologco Register These Currently Available Domains Today Search for your ideal .CO Web Address Get it now before it's gone! Close Notify me when the auction is scheduled for Thank you for inquiring about this premium domain. I'm sorry, but an error occurred. Recently Sold .CO Domains soso.co | $6,400 flip.co | $10,600 ban.co | $24,500 3dtv.co | $5,200 duilawyer.co | $43,000 rollerblades.co | $5,000 socialsecuritydisability.co | $6,900 rakeback.co | $8,550 newcars.co | $8,000 mylawyer.co | $5,100 duiattorney.co | $44,500 fairfield.co | $7,210 paydayloans.co | $9,375 drive.co | $5,110 nos.co | $6,110 What is .CO ? .CO is the new web address that gives you a truly global, recognizable, and credible option for branding your online presence.

Learning Scala in small bites Learning with the REPL One of the useful features for learning Scala is its REPL (read-eval-print-loop) support. If you want to try something out in Scala, just run: % scala and then try it out at the prompt. Examples Each well-commented script below demonstrates a different facet of Scala. [Values.scala] #! /* Scala has a rich set of value types, and a rich literal syntax to support them // Integers:val anInt = 3 // Floating point:val aDouble = 4.0 // Charaters:val aCharacter = 'c' // Strings:val aString = "Google" // Symbols:val aSymbol = 'foo // XML:val anXMLElement = <a href=" // Tuples:val aPair = (aString,aDouble) // Lists:val aList = List(1,2,3,4) // Ranges:val aRange = 1 to 5 // Maps:val aMap = Map(3 -> "foo", 4 -> "bar") // Sets:val aSet = Set(8,9,10) // Arrays:val anArray = Array(1,2,3,5) // Unit:val unit = () // Null:val nullValue = null // Functions:def incImplicit(x : Int ) = x + 1 val incAnonymous = ((x : Int) => x + 1) [Functions.scala] // f(x) => f.apply(x)

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.

Real-World Scala: Dependency Injection (DI) ← Posted: 2008-10-06 In this second post in the Real-World Scala series I am going to discuss how to implement/achieve Depenency Injection (DI) in Scala. Scala is a very rich and deep language that gives you several ways of doing DI solely based on language constructs, but nothing prevents you from using existing Java DI frameworks, if that is preferred. Using the Cake Pattern The current strategy we are using is based on the so-called Cake Pattern. Note: I will try to explain things in steps which I refactor towards the final version (this is only to help with the understanding), so please wait with yelling: “This sucks!” First, let’s create a UserRepository (DAO) implementation. Here we could have split up the implementation in a trait interface and its implementation, but in order to keep things simple I didn’t see the need. Now let’s create a user service (also a dummy one, merely redirecting to our repository). Here you can see that we are referencing an instance of the UserRepository.

Scala Documentation - Scala Documentation Testing Akka with Specs2 This year I have been working on several systems based on Akka, usually in combination with the excellent Spray framework to build fully asynchronous actor-driven REST servers. All in all this has been going very well but recently I had to reinvent a certain wheel for the third time (on the third project) so I thought it might be good to blog about it so others can benefit from it too. The problem is very simple: Akka has great unit test support but unfortunately (for me) that support is based on ScalaTest. Based on that original example, here is my slightly improved and commented version: Using this little Specs2 context trick bridges the two systems, allowing you to write normal Akka TestKit-based tests but using Specs2 as the test driver and matcher library.

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. 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. The difference between the two implicit conversions on arrays is shown in the next REPL dialogue: You see that calling reverse on seq, which is a WrappedArray, will give again a WrappedArray. Next: Strings

Related: