Scala 生态圈 (scala ecosystem)

Download Scala 生态圈 (scala ecosystem)

Post on 01-Dec-2014

238 views

Category:

Science

9 download

Embed Size (px)

DESCRIPTION

scala frameworksIDEbuild toolslibraries

TRANSCRIPT

<ul><li> 1. SCALA ! @make_dream ! hwpeng@thoughtworks.com </li> <li> 2. SCALA 2 A. B. Hello World C. </li> <li> 3. SCALA 3 1958 - 09 - 05 Typesafe Inc. Java ScalaMOOC Martin Odersky </li> <li> 4. SCALA 4 2001Scala EPFL 2004Java 20046.NET 20063Scala 2.0 Java 20115OderskyJonas Bonr Typesafe 2012 Scala .NET 2014Scala 2.11.2 </li> <li> 5. YOU DONT KNOW WHAT YOU DONT KNOW As a developer, 5 </li> <li> 6. AWESOME SCALA 6 </li> <li> 7. BUILD TOOL - MAVEN 7 scala-tools.orgScala-tools Maven2 Repositoryhttp://scala-tools.org/repo-releasesscala-tools.orgScala-tools Maven2 Repositoryhttp://scala-tools.org/repo-releasesorg.scala-langscala-library2.11.1org.scala-toolsmaven-scala-plugincompile</li> <li> 8. BUILD TOOL - GRADLE 8 apply plugin: 'scala' repositories { mavenCentral() } dependencies { compile 'org.scala-lang:scala-library:2.11.1' } </li> <li> 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") </li> <li> 10. DB - SCALIKEJDBC 10 PostgreSQLMySQLH2HSQLDBOracleSQL 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 </li> <li> 11. DB - SQUERYL 11 PostgresOracleMySQLH2DB2SQL ServerDerby def songCountByArtistId: Query[GroupWithMeasures[Long, Long]] = from(artists, songs)((a, s) =&gt; 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 </li> <li> 12. DB - SLICK 12 DerbyH2HSQLDBAccessMySQLPostgreSQLSQLite OracleDB2 SQL Server val q = coffees.filter(_.price &gt; 20) .sortBy(_.name.desc) .drop(10) .take(5) SELECT * FROM coffees WHERE price &gt; 20 ORDER BY name DESC LIMIT 5 OFFSET 10 </li> <li> 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") } } </li> <li> 14. WEB - *ATRA 14 </li> <li> 15. WEB - LIFT 15 View First </li> <li> 16. TEST - SCALACHECK 16 Test object StringSpec extends Properties("String") { property("startWith") = forAll { (a: String, b: String) =&gt; (a + b).startsWith(a) } property("concatenate") = forAll { (a: String, b: String) =&gt; (a + b).length &gt; a.length &amp;&amp; (a + b).length &gt; b.length } } Result + String.startWith: OK, passed 100 tests. ! String.concat: Falsified after 0 passed tests. &gt; ARG_0: "" &gt; ARG_1: "" ! </li> <li> 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") } } } </li> <li> 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)) } </li> <li> 19. DISTRIBUTED SYSTEM 19 </li> <li> 20. BIG DATA 20 100x faster than Hadoop MapReduce in memory 10x faster on disk. </li> <li> 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/ </li> <li> 22. AD CourseraFunctional Programming Principles in ScalaScala Martin Odersky 22 https://www.coursera.org/course/progfun </li> <li> 23. Q&amp;A </li> </ul>