SlideShare a Scribd company logo
1 of 23
Download to read offline
SCALA ⽣生态圈 
彭洪伟 
! 
@make_dream 
! 
hwpeng@thoughtworks.com
SCALA 知多少 
2 
▫︎A. 仅仅听过该名词,或更少 
▫︎B. 了解过基本语法,有 Hello World 经验 
▫︎C. 了解⽐比较多,有项⺫⽬目经验
SCALA 起源 
3 
▫︎出⽣生⽇日期:1958 - 09 - 05 
▫︎国籍:德国 
▫︎⺟母校:苏黎世联邦理⼯工学院 
▫︎公司:Typesafe Inc. 
▫︎成就:Java 泛型、Scala、MOOC 
Martin Odersky
SCALA ⼤大事记 
4 
▫︎2001年,Scala 的设计在 EPFL 开始; 
▫︎2004年初,Java 版发布; 
▫︎2004年6⽉月,.NET 版发布; 
▫︎2006年3⽉月,Scala 2.0 Java 版发布; 
▫︎2011年5⽉月,Odersky和Jonas Bonér 创办 Typesafe; 
▫︎2012年,官⽅方停⽌止维护 Scala .NET 版; 
▫︎2014年,Scala 2.11.2 发布。
YOU DON’T KNOW 
WHAT YOU DON’T 
KNOW 
As a developer, 最可怕的事情是什么? 
5
AWESOME SCALA 
6
BUILD TOOL - MAVEN 
7 
<repository> 
<id>scala-tools.org</id> 
<name>Scala-tools Maven2 Repository</name> 
<url>http://scala-tools.org/repo-releases</url> 
</repository> 
<pluginRepository> 
<id>scala-tools.org</id> 
<name>Scala-tools Maven2 Repository</name> 
<url>http://scala-tools.org/repo-releases</url> 
</pluginRepository> 
<dependency> 
<groupId>org.scala-lang</groupId> 
<artifactId>scala-library</artifactId> 
<version>2.11.1</version> 
</dependency> 
<plugin> 
<groupId>org.scala-tools</groupId> 
<artifactId>maven-scala-plugin</artifactId> 
<executions> 
<execution> 
<goals> 
<goal>compile</goal> 
</goals> 
</execution> 
</executions> 
</plugin>
BUILD TOOL - GRADLE 
8 
apply plugin: 'scala' 
repositories { 
mavenCentral() 
} 
dependencies { 
compile 'org.scala-lang:scala-library:2.11.1' 
}
BUILD TOOL - SBT 
9 
http://www.scala-sbt.org/ 
name := "hello world" 
version := "0.0.1" 
scalaVersion := "2.11.1" 
resolvers ++= Seq ( 
Resolver.mavenLocal, 
Resolver.sonatypeRepo ("releases"), 
Resolver.typesafeRepo ("releases") 
) 
libraryDependencies ++= 
Seq ("org.scala-lang" % "scala-compiler" % "2.11.1") 
addSbtPlugin ("com.typesafe.play" % "sbt-plugin" % "2.3.1")
DB - SCALIKEJDBC 
10 
PostgreSQL、MySQL、H2、HSQLDB、Oracle、SQL Server… … 
val orders: List[Order] = withSQL { 
select 
.from(Order as o) 
.innerJoin(Product as p).on(o.productId, p.id) 
.leftJoin(Account as a).on(o.accountId, a.id) 
.where.eq(o.productId, 123) 
.orderBy(o.id).desc 
.limit(4) 
.offset(0) 
}.map(Order(o, p, a)).list.apply() 
SELECT 
o.*, p.*, a.* 
FROM 
orders o 
INNER JOIN products p ON o.product_id = p.id 
LEFT JOIN accounts a ON o.account_id = a.id 
WHERE o.product_id = 123 
ORDER BY o.id DESC 
LIMIT 4 
OFFSET 0
DB - SQUERYL 
11 
Postgres、Oracle、MySQL、H2、DB2、SQL Server、Derby 
def songCountByArtistId: Query[GroupWithMeasures[Long, Long]] = 
from(artists, songs)((a, s) => 
where(a.id === s.artistId) 
groupBy (a.id) 
compute (countDistinct(s.id)) 
) 
SELECT 
Artist1.id AS g0, count(DISTINCT Song2.id) AS c0 
FROM 
Artist Artist1, Song Song2 
WHERE 
(Artist1.id = Song2.artistId) 
GROUP BY 
Artist1.id
DB - SLICK 
12 
Derby、H2、HSQLDB、Access、MySQL、PostgreSQL、SQLite、 
Oracle、DB2 、SQL Server 
val q = coffees.filter(_.price > 20) 
.sortBy(_.name.desc) 
.drop(10) 
.take(5) 
SELECT 
* 
FROM 
coffees 
WHERE 
price > 20 
ORDER BY 
name DESC 
LIMIT 5 
OFFSET 10
WEB - PLAY 
13 
route 
GET /hello/:username HelloController.say(username: String) 
controller 
import play.api.mvc.{Action, Controller} 
object HelloController extends Controller { 
def say(username: String) = Action { 
Ok(s"hello, $username") 
} 
}
WEB - *ATRA 
14
WEB - LIFT 
15 
View First
TEST - SCALACHECK 
16 
Test 
object StringSpec extends Properties("String") { 
property("startWith") = forAll { (a: String, b: String) => 
(a + b).startsWith(a) 
} 
property("concatenate") = forAll { (a: String, b: String) => 
(a + b).length > a.length && (a + b).length > b.length 
} 
} 
Result 
+ String.startWith: OK, passed 100 tests. 
! String.concat: Falsified after 0 passed tests. 
> ARG_0: "" 
> ARG_1: "" 
!
TEST - SPEC2 
17 
Test 
import org.specs2.mutable._ 
class HelloWorldSpec extends Specification { 
"The 'Hello world' string" should { 
"contain 11 characters" in { 
"Hello world" must have size(11) 
} 
"start with 'Hello'" in { 
"Hello world" must startWith("Hello") 
} 
"end with 'world'" in { 
"Hello world" must endWith("world") 
} 
} 
}
TEST - GATLING 
18 
class BasicSimulation extends Simulation { 
val httpConf = http.baseURL("http://tax.myhpsnet.com:8800") 
val scn = scenario("BasicSimulation") 
.exec(http("get an invoice") 
.get("/api/invoices/d361bb03-e762-3842-b6ae-a3062d1e5cf7")) 
.pause(1) 
setUp(scn.inject(atOnceUsers(100)).protocols(httpConf)) 
}
DISTRIBUTED SYSTEM 
19
BIG DATA 
20 
100x faster than Hadoop MapReduce in memory 
10x faster on disk.
REFERENCES 
21 
1. http://en.wikipedia.org/wiki/Martin_Odersky 
2. http://en.wikipedia.org/wiki/Scala_(programming_language) 
3. http://www.infoq.com/cn/articles/scala-technology 
4. https://github.com/lauris/awesome-scala 
5. http://agiledon.github.io/blog/2014/01/13/testing-styles-of-scalatest/ 
6. http://agiledon.github.io/blog/2014/07/20/scala-resource/
AD 
Coursera上有⼀一⻔门免费的课程叫Functional 
Programming Principles in Scala,由Scala 
的作者Martin Odersky主讲。 
22 
https://www.coursera.org/course/progfun
Q&A

More Related Content

What's hot

PHP Loves MongoDB - Dublin MUG (by Hannes)
PHP Loves MongoDB - Dublin MUG (by Hannes)PHP Loves MongoDB - Dublin MUG (by Hannes)
PHP Loves MongoDB - Dublin MUG (by Hannes)Mark Hillick
 
Slaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubySlaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubyJason Yeo Jie Shun
 
The Ring programming language version 1.5.4 book - Part 181 of 185
The Ring programming language version 1.5.4 book - Part 181 of 185The Ring programming language version 1.5.4 book - Part 181 of 185
The Ring programming language version 1.5.4 book - Part 181 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 50 of 202
The Ring programming language version 1.8 book - Part 50 of 202The Ring programming language version 1.8 book - Part 50 of 202
The Ring programming language version 1.8 book - Part 50 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180Mahmoud Samir Fayed
 

What's hot (11)

7li7w devcon5
7li7w devcon57li7w devcon5
7li7w devcon5
 
PHP Loves MongoDB - Dublin MUG (by Hannes)
PHP Loves MongoDB - Dublin MUG (by Hannes)PHP Loves MongoDB - Dublin MUG (by Hannes)
PHP Loves MongoDB - Dublin MUG (by Hannes)
 
Slaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubySlaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in Ruby
 
JavaScript Obfuscation
JavaScript ObfuscationJavaScript Obfuscation
JavaScript Obfuscation
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
ES6 at PayPal
ES6 at PayPalES6 at PayPal
ES6 at PayPal
 
The Ring programming language version 1.5.4 book - Part 181 of 185
The Ring programming language version 1.5.4 book - Part 181 of 185The Ring programming language version 1.5.4 book - Part 181 of 185
The Ring programming language version 1.5.4 book - Part 181 of 185
 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210
 
Potential Friend Finder
Potential Friend FinderPotential Friend Finder
Potential Friend Finder
 
The Ring programming language version 1.8 book - Part 50 of 202
The Ring programming language version 1.8 book - Part 50 of 202The Ring programming language version 1.8 book - Part 50 of 202
The Ring programming language version 1.8 book - Part 50 of 202
 
The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180
 

Similar to Scala 生态圈 (scala ecosystem)

Spark Summit EU talk by Ted Malaska
Spark Summit EU talk by Ted MalaskaSpark Summit EU talk by Ted Malaska
Spark Summit EU talk by Ted MalaskaSpark Summit
 
Scala introduction
Scala introductionScala introduction
Scala introductionvito jeng
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)jeffz
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghStuart Roebuck
 
Kotlin: maybe it's the right time
Kotlin: maybe it's the right timeKotlin: maybe it's the right time
Kotlin: maybe it's the right timeDavide Cerbo
 
Plone For Developers - World Plone Day, 2009
Plone For Developers - World Plone Day, 2009Plone For Developers - World Plone Day, 2009
Plone For Developers - World Plone Day, 2009Core Software Group
 
Scala & sling
Scala & slingScala & sling
Scala & slingmichid
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know Norberto Leite
 
Mongo+java (1)
Mongo+java (1)Mongo+java (1)
Mongo+java (1)MongoDB
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
MapReduce with Scalding @ 24th Hadoop London Meetup
MapReduce with Scalding @ 24th Hadoop London MeetupMapReduce with Scalding @ 24th Hadoop London Meetup
MapReduce with Scalding @ 24th Hadoop London MeetupLandoop Ltd
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalMichael Stal
 
The Ring programming language version 1.5.4 book - Part 15 of 185
The Ring programming language version 1.5.4 book - Part 15 of 185The Ring programming language version 1.5.4 book - Part 15 of 185
The Ring programming language version 1.5.4 book - Part 15 of 185Mahmoud Samir Fayed
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvmIsaias Barroso
 

Similar to Scala 生态圈 (scala ecosystem) (20)

Spark Summit EU talk by Ted Malaska
Spark Summit EU talk by Ted MalaskaSpark Summit EU talk by Ted Malaska
Spark Summit EU talk by Ted Malaska
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Kotlin: maybe it's the right time
Kotlin: maybe it's the right timeKotlin: maybe it's the right time
Kotlin: maybe it's the right time
 
Plone For Developers - World Plone Day, 2009
Plone For Developers - World Plone Day, 2009Plone For Developers - World Plone Day, 2009
Plone For Developers - World Plone Day, 2009
 
Command Liner with Scala
Command Liner with ScalaCommand Liner with Scala
Command Liner with Scala
 
Scala & sling
Scala & slingScala & sling
Scala & sling
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
Mongo+java (1)
Mongo+java (1)Mongo+java (1)
Mongo+java (1)
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
[Start] Scala
[Start] Scala[Start] Scala
[Start] Scala
 
Play á la Rails
Play á la RailsPlay á la Rails
Play á la Rails
 
MapReduce with Scalding @ 24th Hadoop London Meetup
MapReduce with Scalding @ 24th Hadoop London MeetupMapReduce with Scalding @ 24th Hadoop London Meetup
MapReduce with Scalding @ 24th Hadoop London Meetup
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
 
The Ring programming language version 1.5.4 book - Part 15 of 185
The Ring programming language version 1.5.4 book - Part 15 of 185The Ring programming language version 1.5.4 book - Part 15 of 185
The Ring programming language version 1.5.4 book - Part 15 of 185
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
 
Kotlin
KotlinKotlin
Kotlin
 

Recently uploaded

Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...RohitNehra6
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Patrick Diehl
 
Botany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdfBotany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdfSumit Kumar yadav
 
Broad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptxBroad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptxjana861314
 
Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfSumit Kumar yadav
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfmuntazimhurra
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bSérgio Sacani
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhousejana861314
 
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCESTERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCEPRINCE C P
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxkessiyaTpeter
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoSérgio Sacani
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPirithiRaju
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTSérgio Sacani
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Nistarini College, Purulia (W.B) India
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...anilsa9823
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...Sérgio Sacani
 
Boyles law module in the grade 10 science
Boyles law module in the grade 10 scienceBoyles law module in the grade 10 science
Boyles law module in the grade 10 sciencefloriejanemacaya1
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksSérgio Sacani
 

Recently uploaded (20)

The Philosophy of Science
The Philosophy of ScienceThe Philosophy of Science
The Philosophy of Science
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?
 
Botany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdfBotany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdf
 
Broad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptxBroad bean, Lima Bean, Jack bean, Ullucus.pptx
Broad bean, Lima Bean, Jack bean, Ullucus.pptx
 
Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdf
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdf
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhouse
 
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
 
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCESTERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on Io
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
 
Boyles law module in the grade 10 science
Boyles law module in the grade 10 scienceBoyles law module in the grade 10 science
Boyles law module in the grade 10 science
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
 

Scala 生态圈 (scala ecosystem)

  • 1. SCALA ⽣生态圈 彭洪伟 ! @make_dream ! hwpeng@thoughtworks.com
  • 2. SCALA 知多少 2 ▫︎A. 仅仅听过该名词,或更少 ▫︎B. 了解过基本语法,有 Hello World 经验 ▫︎C. 了解⽐比较多,有项⺫⽬目经验
  • 3. SCALA 起源 3 ▫︎出⽣生⽇日期:1958 - 09 - 05 ▫︎国籍:德国 ▫︎⺟母校:苏黎世联邦理⼯工学院 ▫︎公司:Typesafe Inc. ▫︎成就:Java 泛型、Scala、MOOC Martin Odersky
  • 4. SCALA ⼤大事记 4 ▫︎2001年,Scala 的设计在 EPFL 开始; ▫︎2004年初,Java 版发布; ▫︎2004年6⽉月,.NET 版发布; ▫︎2006年3⽉月,Scala 2.0 Java 版发布; ▫︎2011年5⽉月,Odersky和Jonas Bonér 创办 Typesafe; ▫︎2012年,官⽅方停⽌止维护 Scala .NET 版; ▫︎2014年,Scala 2.11.2 发布。
  • 5. YOU DON’T KNOW WHAT YOU DON’T KNOW As a developer, 最可怕的事情是什么? 5
  • 7. BUILD TOOL - MAVEN 7 <repository> <id>scala-tools.org</id> <name>Scala-tools Maven2 Repository</name> <url>http://scala-tools.org/repo-releases</url> </repository> <pluginRepository> <id>scala-tools.org</id> <name>Scala-tools Maven2 Repository</name> <url>http://scala-tools.org/repo-releases</url> </pluginRepository> <dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId> <version>2.11.1</version> </dependency> <plugin> <groupId>org.scala-tools</groupId> <artifactId>maven-scala-plugin</artifactId> <executions> <execution> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin>
  • 8. BUILD TOOL - GRADLE 8 apply plugin: 'scala' repositories { mavenCentral() } dependencies { compile 'org.scala-lang:scala-library:2.11.1' }
  • 9. BUILD TOOL - SBT 9 http://www.scala-sbt.org/ name := "hello world" version := "0.0.1" scalaVersion := "2.11.1" resolvers ++= Seq ( Resolver.mavenLocal, Resolver.sonatypeRepo ("releases"), Resolver.typesafeRepo ("releases") ) libraryDependencies ++= Seq ("org.scala-lang" % "scala-compiler" % "2.11.1") addSbtPlugin ("com.typesafe.play" % "sbt-plugin" % "2.3.1")
  • 10. DB - SCALIKEJDBC 10 PostgreSQL、MySQL、H2、HSQLDB、Oracle、SQL Server… … val orders: List[Order] = withSQL { select .from(Order as o) .innerJoin(Product as p).on(o.productId, p.id) .leftJoin(Account as a).on(o.accountId, a.id) .where.eq(o.productId, 123) .orderBy(o.id).desc .limit(4) .offset(0) }.map(Order(o, p, a)).list.apply() SELECT o.*, p.*, a.* FROM orders o INNER JOIN products p ON o.product_id = p.id LEFT JOIN accounts a ON o.account_id = a.id WHERE o.product_id = 123 ORDER BY o.id DESC LIMIT 4 OFFSET 0
  • 11. DB - SQUERYL 11 Postgres、Oracle、MySQL、H2、DB2、SQL Server、Derby def songCountByArtistId: Query[GroupWithMeasures[Long, Long]] = from(artists, songs)((a, s) => where(a.id === s.artistId) groupBy (a.id) compute (countDistinct(s.id)) ) SELECT Artist1.id AS g0, count(DISTINCT Song2.id) AS c0 FROM Artist Artist1, Song Song2 WHERE (Artist1.id = Song2.artistId) GROUP BY Artist1.id
  • 12. DB - SLICK 12 Derby、H2、HSQLDB、Access、MySQL、PostgreSQL、SQLite、 Oracle、DB2 、SQL Server val q = coffees.filter(_.price > 20) .sortBy(_.name.desc) .drop(10) .take(5) SELECT * FROM coffees WHERE price > 20 ORDER BY name DESC LIMIT 5 OFFSET 10
  • 13. WEB - PLAY 13 route GET /hello/:username HelloController.say(username: String) controller import play.api.mvc.{Action, Controller} object HelloController extends Controller { def say(username: String) = Action { Ok(s"hello, $username") } }
  • 15. WEB - LIFT 15 View First
  • 16. TEST - SCALACHECK 16 Test object StringSpec extends Properties("String") { property("startWith") = forAll { (a: String, b: String) => (a + b).startsWith(a) } property("concatenate") = forAll { (a: String, b: String) => (a + b).length > a.length && (a + b).length > b.length } } Result + String.startWith: OK, passed 100 tests. ! String.concat: Falsified after 0 passed tests. > ARG_0: "" > ARG_1: "" !
  • 17. TEST - SPEC2 17 Test import org.specs2.mutable._ class HelloWorldSpec extends Specification { "The 'Hello world' string" should { "contain 11 characters" in { "Hello world" must have size(11) } "start with 'Hello'" in { "Hello world" must startWith("Hello") } "end with 'world'" in { "Hello world" must endWith("world") } } }
  • 18. TEST - GATLING 18 class BasicSimulation extends Simulation { val httpConf = http.baseURL("http://tax.myhpsnet.com:8800") val scn = scenario("BasicSimulation") .exec(http("get an invoice") .get("/api/invoices/d361bb03-e762-3842-b6ae-a3062d1e5cf7")) .pause(1) setUp(scn.inject(atOnceUsers(100)).protocols(httpConf)) }
  • 20. BIG DATA 20 100x faster than Hadoop MapReduce in memory 10x faster on disk.
  • 21. REFERENCES 21 1. http://en.wikipedia.org/wiki/Martin_Odersky 2. http://en.wikipedia.org/wiki/Scala_(programming_language) 3. http://www.infoq.com/cn/articles/scala-technology 4. https://github.com/lauris/awesome-scala 5. http://agiledon.github.io/blog/2014/01/13/testing-styles-of-scalatest/ 6. http://agiledon.github.io/blog/2014/07/20/scala-resource/
  • 22. AD Coursera上有⼀一⻔门免费的课程叫Functional Programming Principles in Scala,由Scala 的作者Martin Odersky主讲。 22 https://www.coursera.org/course/progfun
  • 23. Q&A