background preloader

Effective Scala

Effective Scala
Table of Contents Other languages 日本語Русский简体中文 Introduction Scala is one of the main application programming languages used at Twitter. Much of our infrastructure is written in Scala and we have several large libraries supporting our use. 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. Whitespace Indent by two spaces. Naming to Use

Scala School Other Languages: About Scala school started as a series of lectures at Twitter to prepare experienced engineers to be productive Scala programmers. 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:

Observable · Netflix/RxJava Wiki In RxJava an object of the Subscriber class (or some other object that implements the Observer interface) subscribes to an object of the Observable class. Then that subscriber reacts to whatever item or items the Observable object emits. This pattern facilitates concurrent operations because it does not need to block while waiting for the Observable to emit objects, but instead it creates a sentry in the form of a subscriber that stands ready to react appropriately at whatever future time the Observable does so. This page explains what the reactive pattern is and what Observables and Subscribers are (and how Subscribers subscribe to Observables). Subsequent child pages (as shown in sidebar) show how you use the variety of Observable operators to link Observables together and change their behaviors. This documentation accompanies its explanations with "marble diagrams." see also Background Here is how the equivalent jeans-buying process might take place in the reactive model: see also:

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.

scala koans Scala Documentation - Scala Documentation 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

Advanced routing in Play Framework - all that jazz We frequently get questions about how to meet all sorts of different routing needs in Play Framework. While the built in router is enough for most users, sometimes you may encounter use cases where it's not enough. Or, maybe you want a more convenient way to implement some routing pattern. Whatever it is, Play will allow you to do pretty much anything. Hooking into Plays routing mechanism If for some reason you don't like Plays router, or if you want to use a modified router, then Play allows you to do this easily. As you can see, I've practically implemented my own little routing DSL here. An interesting thing that could also be done is to delegate to different routers based on something in the request. So here are some use cases that overriding onRouteRequest may be useful for: Modifying the request in some way before routing is donePlugging in a completely different router (eg, jaxrs)Delegating to different routes files based on some aspect of the request Implementing a custom router

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)

Related: