BT

Effective Scala - Best Practices from Twitter

by Bienvenido David on Feb 15, 2012 |

Twitter has open sourced its Effective Scala guide. The document is on GitHub, with the Git repository URL https://github.com/twitter/effectivescala.git. The document is licensed under CC-BY 3.0.

Scala is one of the primary programming languages used at Twitter, and most of the Twitter infrastructure is written in Scala. The Effective Scala guide is a series of short essays, a set of "best practices" learned from using Scala inside Twitter. Twitter's use of Scala is mainly for creating high volume, distributed systems, though most of the guide should be applicable to other domains.

The core ideas in the document are:

  • After correctness, think always of the reader. 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.
  • Program in Scala, not in Java, nor Haskell, nor Python
  • A sophisticated language requires a complex implementation, and complexity begets complexity. Thus complexity is the tax of sophistication - you must always ensure that its utility exceeds its cost.

 

Here are the different topics of the Effective Scala guide, taken from the table of contents.

  • Formatting: Whitespace, Naming, Imports, Braces, Pattern matching, Comments
  • Types and Generics: Return type annotations, Variance, Type aliases, Implicits
  • Collections: Hierarchy, Use, Style, Performance, Java Collections
  • Concurrency: Futures, Collections
  • Control structures: Recursion, Returns, for loops and comprehensions, require and assert
  • Functional programming: Case classes as algebraic data types, Options, Pattern matching, Partial functions, Destructuring bindings, Lazyness, Call by name, flatMap
  • Object oriented programming: Dependency injection, Traits, Visibility, Structural typing
  • Garbage collection
  • Java compatibility

 

The guide assumes you are already familiar with Scala. For users new to Scala, Twitter has made available the written materials for their Scala School, a series of lectures to help introduce Twitter programmers to Scala. The official Learning Scala page is also available from the scala-lang.org website. Another good introduction is Learning Scala in small bites, a series of small examples, each of which highlights one or two aspects of Scala.

Effective Scala is a living document that will continually change to reflect Twitter current "best practices". Users can help improve the guide by creating an issue at the Effective Scala issues page.

Hello stranger!

You need to Register an InfoQ account or to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Thank you by Serge Bureau

Quite useful

Scala done right by Fernando Racca

Thanks for the docs, is great to see Twitter encouraging to use Scala :)

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

2 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT