2015/08/12

[ScaVa->Scala] Introduction to Scala Development

[ScaVa->Scala] Introduction to Scala Development

[ScaVa->Scala] Introduction to Scala Development

前言

這件文件是在公司內部向一些新踏入Scala領域的同事們介紹所使用的資料,因此適合有程式開發經驗,並且想Scala領域中的朋友們。
底下列了一些學習Scala的資源、並列出一些我們自己開發常用到的Libraries並適合新手來學習使用的。
最底下有兩各sample projects,以縮網址為題目來分別實作一個library與提供REST服務的web application。

Scala Introduction

Learning Scala

Functional Programming

Category theory jargon cheat sheet

  • Functor supports map.
  • Applicative functor extends functor and adds pure and <*>.
  • Monad extends applicative and adds flatMap (a.k.a bind).
  • Semigroup supports append.
  • Monoid extends Semigroup and adds zero.

Scala Libraries, Frameworks and Software.

Check most popular scala libraries at GitHub - awesome-scala.

Common use libraries in our development.

  • Distributed System

    • Akka — A toolkit and runtime for building highly concurrent, distributed, and fault tolerant event-driven applications.
  • Database

    • Elastic4s — A scala DSL / reactive client for Elasticsearch
    • ReactiveMongo — Reactive Scala Driver for MongoDB.
    • rediscala — Non-blocking, Reactive Redis driver for Scala (with Sentinel support)
  • Web Framework

    • Play — Makes it easy to build scalable, fast and real-time web applications with Java & Scala.
    • Scalatra — Tiny Scala high-performance, async web framework, inspired by Sinatra.
    • Spray — A suite of scala libraries for building and consuming RESTful web services on top of Akka.
    • Finatra — A sinatra-inspired web framework for scala, running on top of Finagle.
    • Socko — An embedded Scala web server powered by Netty networking and Akka processing.
  • HTTP client

    • Dispatch — Library for asynchronous HTTP interaction. It provides a Scala vocabulary for Java’s async-http-client.
    • Spray — Actor-based library for http interaction.
  • Json

    • json4s — Project aims to provide a single AST to be used by other scala json libraries.
    • jackson-module-scala — Add-on module for Jackson to support Scala-specific datatypes.
  • Config

  • Logger

  • Testing

    • ScalaTest — A testing tool for Scala and Java developers.
    • Gatling – Async Scala-Akka-Netty based Stress Tool.
  • Extensions

    • Scalaz — An extension to the core Scala library for functional programming.
    • Scala Async — An asynchronous programming facility for Scala.
    • Scalactic — Small library of utilities related to quality that helps keeping code clear and correct. (ScalaTest embedded this lib.)

Development Environment

Scala

SBT (Simple Build Tool)

http://www.scala-sbt.org/

Package Plugins http://www.scala-sbt.org/release/docs/Community-Plugins.html

IDE - Intellij Idea

You’re welcome to use any text editor or IDE what you like. e.g. vim, TextMate, Sublime, Notepad++, cloud9…

However my favorite IDE for Scala development is Intellij Idea, which is most powerful IDE for scala development.

Directory Structure

Ref: SBT Directory Structure

source code

src/
  main/
    resources/
       <files to include in main jar here>
    scala/
       <main Scala sources>
    java/
       <main Java sources>
  test/
    resources
       <files to include in test jar here>
    scala/
       <test Scala sources>
    java/
       <test Java sources>

sbt build definition files

build.sbt
project/
  Build.scala

Others

  • Markdown
  • Git
  • Chef

Demo

張貼留言

My World