Node.js vs Play Framework (with Japanese subtitles)

163
Node.js vs Play Framework VS

description

Video: http://www.nicovideo.jp/watch/1410857293 Here's the showdown you've been waiting for: Node.js vs Play Framework. Both are popular open source web frameworks that are built for developer productivity, asynchronous I/O, and the real time web. But which one is easier to learn, test, deploy, debug, and scale? Should you pick Javascript or Scala? The Google v8 engine or the JVM? NPM or Ivy? Grunt or SBT? Two frameworks enter, one framework leaves. This version of the presentation has Japanese subtitles. For the English only version, see http://www.slideshare.net/brikis98/nodejs-vs-play-framework

Transcript of Node.js vs Play Framework (with Japanese subtitles)

Page 1: Node.js vs Play Framework (with Japanese subtitles)

Node.js vs Play Framework

VS

Page 2: Node.js vs Play Framework (with Japanese subtitles)

Node.js: server-side JavaScript runtime environment; open source; single threaded; non-blocking I/O.

Node.js: サーバサイドJSランタイム、OSS、シングルスレッド、非同期 I/O

Page 3: Node.js vs Play Framework (with Japanese subtitles)

express.js: the most popular web framework for Node.js.

express.js: Node.js で一番人気のWebフレームワーク

Page 4: Node.js vs Play Framework (with Japanese subtitles)

Play Framework: Java/Scala web framework; open source; multithreaded; non-blocking I/O.

Play: Java/Scala Webフレームワーク、OSS、マルチスレッド、非同期 I/O

Page 5: Node.js vs Play Framework (with Japanese subtitles)

Former Play Tech Lead at LinkedIn. Long time Node.js user.

Yevgeniy Brikman

元LinkedIn社Play Tech Lead。ベテランNode.jsユーザ

Page 6: Node.js vs Play Framework (with Japanese subtitles)

The framework scorecard

Learn

Develop

Test

Secure

Build

Deploy

Debug

Scale

Maintain

Share

Page 7: Node.js vs Play Framework (with Japanese subtitles)

1

For each feature we discuss...

Much worse than most frameworks

About the same as most frameworks

Much better than most frameworks

510

1 = 酷い、5 = 平均的、10 = 優秀

Page 8: Node.js vs Play Framework (with Japanese subtitles)

The framework scorecard

Learn

Develop

Test

Secure

Build

Deploy

Debug

Scale

Maintain

Share

Page 9: Node.js vs Play Framework (with Japanese subtitles)

Node.js: 1-click installers for every OSOSにかかわらずインストーラは万全

Page 10: Node.js vs Play Framework (with Japanese subtitles)

The “Hello World” Node app: 1 file, 6 lines of code.

var http = require('http');

http.createServer(function (req, res) {

res.writeHead(200, {'Content-Type': 'text/plain'});

res.end('Hello World\n');

}).listen(1337, '127.0.0.1');

console.log('Server running at http://127.0.0.1:1337/');

server.js

Page 11: Node.js vs Play Framework (with Japanese subtitles)

The “Hello World” Express app: 1 file, 8 lines of code.

var express = require('express');

var app = express();

app.get('/', function(req, res){

res.send('Hello World');

});

var server = app.listen(1337, function() {

console.log('Listening on port %d', server.address().port);

});

server.js

Page 12: Node.js vs Play Framework (with Japanese subtitles)

Run using node <filename>. Starts instantly!

Page 13: Node.js vs Play Framework (with Japanese subtitles)

Hit http://localhost:1337 to test

Page 20: Node.js vs Play Framework (with Japanese subtitles)

And much, much more Tons of resources; very gradual learning curve.

リソースが豊富、緩やかな学習曲線

Page 21: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10

Page 22: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10

Page 23: Node.js vs Play Framework (with Japanese subtitles)

Play: download from playframework.com, extract, add activator to your PATH

Play:ダウンロードし、展開し、 activator をPATH に追加する

Page 24: Node.js vs Play Framework (with Japanese subtitles)

Generate a new app using activator new

Page 25: Node.js vs Play Framework (with Japanese subtitles)

The “Hello World” Play app: ~35 files and folders

Page 26: Node.js vs Play Framework (with Japanese subtitles)

Run the app using activator run

Page 27: Node.js vs Play Framework (with Japanese subtitles)

(Downloading all dependencies can take a while the first time around)

初回はjarのダウンロードに時間がかかる

Page 28: Node.js vs Play Framework (with Japanese subtitles)

Hit http://localhost:9000 to test

Page 32: Node.js vs Play Framework (with Japanese subtitles)

Ultimate Guide to Getting Started with Play. Not as many resources; steep learning curve.

リソースが少なめ、急勾配の学習曲線

Page 33: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

Page 34: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

Page 35: Node.js vs Play Framework (with Japanese subtitles)

Routing

GET clients/:id Clients.show(id: Long)

def show(id: Long) = Action { request =>

getClient(id).map { client =>

Ok(views.html.clients.show(client))

}

}

app.get('clients/:id', function(req, res) {

getClient(req.params.id, function(client) {

res.render('show', client);

});

});

RESTful routing. Extracts query & path params.

RESTful routing. Extracts query & path params. Type safe. Actions are composable. Reverse routing.

Page 36: Node.js vs Play Framework (with Japanese subtitles)

Templates

@(name: String, headline: String)

<div class="client">

<h1>@name</h1>

<div class="headline">

Headline: @headline

</div>

</div>

<div class="client">

<h1>{{name}}</h1>

<div class="headline">

Headline: {{headline}}

</div>

</div>

Many template options: handlebars, mustache, dust, jade, etc. Most support client-side rendering!

Twirl templates are compiled into Scala functions: type safe and composable! Other template types via plugins.

Page 37: Node.js vs Play Framework (with Japanese subtitles)

i18n

Translations: i18next-node, i18n-node. Formatting: moment.js, numeral.js.

Translations: Play i18n API. Formatting: Java formatting libraries.

<div class="client">

<h1>{{name}}</h1>

<div class="headline">

{{t "headline.label" headline=headline}}

</div>

</div>

@(name: String, headline: String)

<div class="client">

<h1>@name</h1>

<div class="headline">

Messages("headline.label", headline)

</div>

</div>

Page 38: Node.js vs Play Framework (with Japanese subtitles)

Form binding and validation

Forms, node-formidable, validator.js. Play form binding and validation API.

var regForm = forms.create({

name: fields.string({required: true}),

age: fields.number({min: 18})

});

regForm.handle(req, {

success: function(form) { ... },

error: function(form) { ... }

});

val regForm = Form(mapping(

"name" -> nonEmptyText,

"age" -> number(min = 18)

)(UserData.apply)(UserData.unapply))

regForm.bindFromRequest.fold(

err => BadRequest("Validation error"),

data => Ok(s"Hi $data.name!")

)

Page 39: Node.js vs Play Framework (with Japanese subtitles)

JSON, XML, File Upload

bodyParser, xml2js, node-formidable. Play JSON, XML, File Upload APIs.

// Automatically parse application/json body

app.use(bodyParser.json());

app.post('/clients', function (req, res, next) {

var name = req.body.name;

var age = req.body.age;

res.send(name + " is " + age + " years old.");

});

case class Person(name: String, age: Int)

implicit val prsnFmt = Json.format[Person]

def create = Action(parse.json) { request =>

val person = request.body.as[Person]

Ok(s"$person.name is $person.age years old")

}

POST /clients Clients.create

Page 40: Node.js vs Play Framework (with Japanese subtitles)

Data

Slick, Anorm, Ebean, JPAMySQL, MariaDB, PostgreSLQ, SQLite, Oracle, SQL Server,

DB2, Derby, H2SQLSequelize, Bookshelf.js, node-orm2

MySQL, MariaDB, PostgreSQL, SQLite

NoSQLmongojs/mongoose, cassandra-client, cradle/nano, node_redis, node-neo4j

MongoDB, Cassandra, CouchDB, Redis, Neo4j

ReactiveMongo, DataStax, sprouch, play-plugins-redis, Neo4j-play, JPA

MongoDB, Cassandra, CouchDB, Redis, Neo4j

Cachingnode-memcached, connect-cachememcached, in-memory (not recommended)

play2-memcached, memcontinuationed, Play Cache, ehcache, Guava

memcached, in-memory

Schemasnode-db-migrate, node-migrate Play database evolutions

Page 41: Node.js vs Play Framework (with Japanese subtitles)

Real-time web

socket.io: server & client APIs; WebSockets, Flash Sockets, polling, etc.

Play WebSockets, Comet, and EventSource APIs. Server-side only.

// server code

io.on('connection', function (socket) {

socket.emit('msg', 'Server says hi!');

socket.on('msg', function (msg) { … });

});

def chat = WebSocket.acceptWithActor {

request => out => Props(new Chat(out))

}

class Chat(out: ActorRef) extends Actor {

def receive = {

case m: String => out ! s"Got msg: $m"

}

}

// client code

socket.emit('msg', 'Client says hi!');

socket.on('msg', function (msg) { … });

Page 42: Node.js vs Play Framework (with Japanese subtitles)

● Play is a full stack framework● Express.js is a minimal framework

● You need plugins for most tasks

● Finding good plugins takes time

● Gluing plugins together takes time

● There are defaults for most tasks

● Defaults are mostly high quality

● All defaults can be replaced

Express.js:ミニマル、プラグインを多く使う。 Play:フルスタック

Page 43: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

Page 44: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

Page 46: Node.js vs Play Framework (with Japanese subtitles)

Functional testing: use supertest or call server.listen directly.

var request = require('supertest')

, app = require('express')();

app.get('/user', function(req, res){

res.send(200, { name: 'tobi' });

});

request(app)

.get('/user')

.expect('Content-Type', /json/)

.expect(200);

Page 48: Node.js vs Play Framework (with Japanese subtitles)

Code coverage: Istanbul or Blanket.js

Page 49: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10

Page 50: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10

Page 52: Node.js vs Play Framework (with Japanese subtitles)

Functional testing: use Play’s built-in functional test helpers.

"respond to the index Action" in new App(FakeApplication()) {

val Some(result) = route(FakeRequest(GET, "/Bob"))

status(result) mustEqual OK

contentType(result) mustEqual Some("text/html")

charset(result) mustEqual Some("utf-8")

contentAsString(result) must include ("Hello Bob")

}

Page 53: Node.js vs Play Framework (with Japanese subtitles)

UI testing: use Play’s built-in integration test helpers and built-in Selenium support.

class ExampleSpec extends PlaySpec with OneServerPerSuite with OneBrowserPerSuite {

"The OneBrowserPerTest trait" must {

"provide a web driver" in {

go to (s"http://localhost:$port/testing")

pageTitle mustBe "Test Page"

click on find(name("b")).value

eventually { pageTitle mustBe "scalatest" }

}

}

}

Page 54: Node.js vs Play Framework (with Japanese subtitles)

Code coverage: jacoco4sbt or scct

Page 55: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

Page 56: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

Page 58: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

Page 59: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

Page 60: Node.js vs Play Framework (with Japanese subtitles)

Node.js uses NPM to manage dependencies and basic build commands

{

"name": "Hello World App",

"version": "0.0.3",

"dependencies": {

"express": "4.8.0",

"underscore": "1.6.0"

},

"scripts": {

"test": "node tests/run.js"

}

}

Node.jsは依存性管理や簡単なコマンド定義にNPMを使う

Page 61: Node.js vs Play Framework (with Japanese subtitles)

Many options available for more complicated builds: grunt.js, gulp.js, or broccoli

より複雑なビルドの場合、 grunt.js, gulp.js, broccoliのようなツールを使う

Page 62: Node.js vs Play Framework (with Japanese subtitles)

Thousands of plugins for all common build tasksプラグインが何千もある

Page 63: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10

Page 64: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10

Page 65: Node.js vs Play Framework (with Japanese subtitles)

Play uses SBT as the build system. SBT is an interactive build system.

Play は SBT という対話的ビルドツールを利用

Page 66: Node.js vs Play Framework (with Japanese subtitles)

In SBT, build definitions are written in Scala! … But the learning curve is very steep.

object AppBuild extends Build {

lazy val root = Project(id = "root", base = file(".")).settings(

name := "test-play-app",

version := version,

libraryDependencies += Seq(

"org.scala-tools" % "scala-stm_2.11.1" % "0.3",

"org.apache.derby" % "derby" % "10.4.1.3"

)

)

def version = Option(System.getProperty("version")).getOrElse("0.0.3")

}

ビルドファイルをScalaで書く。でもビギナーには厳しい

Page 67: Node.js vs Play Framework (with Japanese subtitles)

Dependencies are managed using Ivy: familiar, but slow.

Ivyで依存性を管理する。使い慣れてるけど、実行性能は遅め

Page 68: Node.js vs Play Framework (with Japanese subtitles)

Play uses sbt-web to build static content: few plugins; depends on Rhino (slow) or node.js (!).

Playは静的コンテンツのビルドに sbt-webを利用する。プラグインが少ない

Page 69: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

Page 70: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

Page 73: Node.js vs Play Framework (with Japanese subtitles)

Use cluster to run one node instance per CPU

if (cluster.isMaster) {

for (var i = 0; i < numCPUs; i++) {

cluster.fork(); // Fork workers

}

cluster.on('exit', function(worker, code, signal) {

console.log('worker ' + worker.process.pid + ' died');

});

} else {

http.createServer(function(req, res) {

// ...

}).listen(8000);

}

cluster を使ってコア毎にインスタンスを稼働

Page 74: Node.js vs Play Framework (with Japanese subtitles)

Use forever, monit, or Domain to handle crashes.クラッシュ対処

Page 75: Node.js vs Play Framework (with Japanese subtitles)

Configuration: node-config or nconf

var config = require('config');

var host = config.get('dbConfig.host');

{

"dbConfig": {

"host": "localhost",

"port": 5984,

"dbName": "customers"

}

}

server.js

config/default.json

Page 76: Node.js vs Play Framework (with Japanese subtitles)

Use nginx, apache, or ATS to load balance, serve static content, terminate SSL

Client

Data Center

Reverse proxy(e.g. nginx) DB

Static server(e.g. nginx)

Node instanceNode

instanceNode instanceNode

instanceNode instance

Node instanceNode

instanceNode instanceNode

instance

Node instanceNode

instanceNode instanceNode

instance

ロードバランサー、静的コンテンツ、 SSL Termination

Page 77: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8

Page 78: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8

Page 79: Node.js vs Play Framework (with Japanese subtitles)

A few Play-friendly hosting options: Heroku, playframework-cloud, CloudBees

Playをサポートするホスティング

Page 81: Node.js vs Play Framework (with Japanese subtitles)

Use the SBT Native Packager to package the app as tgz, deb, RPM, etc.

Appをネイティブパッケージとして包装できる

Page 82: Node.js vs Play Framework (with Japanese subtitles)

Configuration: Play comes with Typesafe Config

val host = Play.current.configuration.getString("dbConfig.host")

dbConfig = {

host: "localhost",

port: 5984,

dbName: "customers"

}

app/controllers/Application.scala

conf/application.conf

Page 83: Node.js vs Play Framework (with Japanese subtitles)

Use nginx, apache, or ATS to load balance, serve static content, terminate SSL

Client

Data Center

Reverse proxy(e.g. nginx)

Play app

DB

Static server(e.g. nginx)

Play app

Play app

Page 84: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8 7

Page 85: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8 7

Page 86: Node.js vs Play Framework (with Japanese subtitles)

Node.js: use IntelliJ or node-inspector to debugNode.js:IntelliJでデバッグできる

Page 88: Node.js vs Play Framework (with Japanese subtitles)

Use winston, log4js, or bunyan for logging

var winston = require("winston");

winston.info("CHILL WINSTON! ... I put it in the logs.");

Page 89: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8 7

10

Page 90: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8 7

10

Page 91: Node.js vs Play Framework (with Japanese subtitles)

Play runs on the JVM, so you can use your favorite IDE to debug: IntelliJ, Eclipse, NetBeans

Play:好きなIDEを使える

Page 92: Node.js vs Play Framework (with Japanese subtitles)

In dev, Play shows errors right in the browser開発モードでエラーがブラウザで表示される

Page 95: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8 7

10 10

Page 96: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8 7

10 10

Page 97: Node.js vs Play Framework (with Japanese subtitles)

Part 1: scaling for lots of traffic

大量のトラフィックのためのスケーリング

Page 98: Node.js vs Play Framework (with Japanese subtitles)

TechEmpower benchmarks. Warning: microbenchmarks are not a substitute for real world perf testing!

Page 102: Node.js vs Play Framework (with Japanese subtitles)

LinkedIn experience #1: Play and Node.js are very fast in a service oriented architecture with NIO.

Internet Load Balancer

Frontend Server

Frontend Server

Frontend Server

Backend Server

Backend Server

Backend Server

Backend Server

Backend Server

Data Store

Data Store

Data Store

Data Store

LinkedInの感想:Node.jsもPlayもとても速い

Page 103: Node.js vs Play Framework (with Japanese subtitles)

LinkedIn experience #2: Play is ok with blocking I/O & CPU/memory bound use cases. Node.js is not.

// BAD: write files synchronously

fs.writeFileSync('message.txt', 'Hello Node');

console.log("It's saved, but you just blocked ALL requests!");

// Good: write files asynchronously

fs.writeFile('message.txt', 'Hello Node', function (err) {

console.log("It's saved and the server remains responsive!");

});

同期I/O、高メモリ使用率と高CPU使用率の場合、Node.jsの性能が落ちる

Page 104: Node.js vs Play Framework (with Japanese subtitles)

Part 2: scaling for large teams and projects

大きいチーム・プロジェクトのためのスケーリング

Page 105: Node.js vs Play Framework (with Japanese subtitles)

Node.js: best for small projects, short projects, small teams.

Node.js:小さいプロジェクト、短いプロジェクト、小さいチームにいい

Page 106: Node.js vs Play Framework (with Japanese subtitles)

Play: best for longer projects. Slower ramp up, but scales well with team & project size.

Play:より大きいプロジェクトにスケールできる

Page 107: Node.js vs Play Framework (with Japanese subtitles)

For comparison: Spring MVC

Page 108: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8 7

10

10

10

10

Page 109: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8 7

10

10

10

10

Page 110: Node.js vs Play Framework (with Japanese subtitles)

Maintenance: the good partsメンテナンス:「良いパーツ」

Page 111: Node.js vs Play Framework (with Japanese subtitles)

Functional programming: first class functions, closures, underscore.js

関数型プログラミング

Page 112: Node.js vs Play Framework (with Japanese subtitles)

JavaScript is ubiquitous...JSは至る所にある

Page 113: Node.js vs Play Framework (with Japanese subtitles)

...Which means you can share developers, practices, and even code: rendr, derby, meteor

そのため、デベロッパー、情報、コードは入手しやすい

Page 114: Node.js vs Play Framework (with Japanese subtitles)

Node core is stable and mature. Bugs, regressions, and backwards incompatibility are rare.

安定したコア。バグや後方互換性の問題は比較的少ない

Page 115: Node.js vs Play Framework (with Japanese subtitles)

Maintenance: the bad parts

メンテナンス:「悪いパーツ」

Page 116: Node.js vs Play Framework (with Japanese subtitles)
Page 117: Node.js vs Play Framework (with Japanese subtitles)

'' == '0' // false

0 == '' // true

0 == '0' // true

false == 'false' // false

false == '0' // true

false == undefined // false

false == null // false

null == undefined // true

' \t\r\n ' == 0 // true

Bad Parts

Page 118: Node.js vs Play Framework (with Japanese subtitles)

// Default scope is global

var foo = "I'm a global variable!"

// Setting undeclared variables puts them in global scope too

bar = "I'm also a global variable!";

if (foo) {

// Look ma, no block scope!

var baz = "Believe it or not, I'll also be a global variable!"

}

Awful Parts

Page 121: Node.js vs Play Framework (with Japanese subtitles)

doSomethingAsync(req1, function(err1, res1) {

doSomethingAsync(req2, function(err2, res2) {

doSomethingAsync(req3, function(err3, res3) {

doSomethingAsync(req4, function(err4, res4) {

// ...

});

});

});

});

Callback hell: control flow, error handling, and composition are all difficult

コールバック地獄

Page 122: Node.js vs Play Framework (with Japanese subtitles)

Many NPM packages are NOT stable or mature.Incompatibility + bugs + dynamic typing = pain.

NPMに不安定なパッケージが多い。非互換性 + バグ + 動的型付け = 苦痛

Page 123: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8 7

10

10

10

10

3

Page 124: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8 7

10

10

10

10

3

Page 125: Node.js vs Play Framework (with Japanese subtitles)

Maintenance: the good parts

Page 126: Node.js vs Play Framework (with Japanese subtitles)

Functional programming

def sort(a: List[Int]): List[Int] = {

if (a.length < 2) a

else {

val pivot = a(a.length / 2)

sort(a.filter(_ < pivot)) :::

a.filter(_ == pivot) :::

sort(a.filter(_ > pivot))

}

}

Page 127: Node.js vs Play Framework (with Japanese subtitles)

Powerful type system

Page 128: Node.js vs Play Framework (with Japanese subtitles)

Very expressive: case classes, pattern matching, lazy, option, implicits

val NameTagPattern = "Hello, my name is (.+) (.+)".r

val ListPattern = "Last: (.+). First: (.+).".r

// Case classes automatically generate immutable fields, equals, hashCode, constructor

case class Name(first: String, last: String)

// Use Option to avoid returning null if there is no name found

def extractName(str: String): Option[Name] = {

Option(str).collectFirst {

// Pattern matching on regular expressions

case NameTagPattern(fname, lname) => Name(fname, lname)

case ListPattern(lname, fname) => Name(fname, lname)

}

}

表現力が高い

Page 129: Node.js vs Play Framework (with Japanese subtitles)

Runs on the JVM; interop with Java.

Page 131: Node.js vs Play Framework (with Japanese subtitles)

No callback hell!

def index = Action {

// Make 3 sequential, async calls

for {

foo <- WS.url(url1).get()

bar <- WS.url(url2).get()

baz <- WS.url(url3).get()

} yield {

// Build a result using foo, bar, and baz

}

}

Page 132: Node.js vs Play Framework (with Japanese subtitles)

Good IDE support

Page 133: Node.js vs Play Framework (with Japanese subtitles)

Maintenance: the bad parts

Page 134: Node.js vs Play Framework (with Japanese subtitles)

Slow compilerコンパイラ遅い

Page 135: Node.js vs Play Framework (with Japanese subtitles)

Fortunately, Play/SBT support incremental compilation and hot reload!

Play/sbt はインクリメンタルコンパイラと hot reloading があるから大丈夫!

Page 136: Node.js vs Play Framework (with Japanese subtitles)

Complexity

Page 137: Node.js vs Play Framework (with Japanese subtitles)

More complexity

Page 138: Node.js vs Play Framework (with Japanese subtitles)

Play is stable, but not mature: backwards incompatible API changes every release.

Play は安定だがまだ成長期。APIはよく変わる

Page 139: Node.js vs Play Framework (with Japanese subtitles)

Even worse: Scala is not binary compatible between releases!

Scala はリリース間でバイナリ互換性を持たない!

Page 140: Node.js vs Play Framework (with Japanese subtitles)

Backwards incompatibility = pain.… Static typing makes it a little more manageable.

バイナリ互換性が無いのは辛いけど、静的な型によって少しは緩和される

Page 141: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8 7

10

10

10

10

3 8

Page 142: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8 7

10

10

10

10

3 8

Page 143: Node.js vs Play Framework (with Japanese subtitles)

351Contributors544

Watchers2,376 576

Stars31,332 5,077

Github activity as of 08/10/14

Forks6,970 1,872

PR’s3,066 2,201

Page 144: Node.js vs Play Framework (with Japanese subtitles)

10,698StackOverflow Questions53,555

Google Group Members14,199 11,577

Google Group Posts/Month ~400 ~1,100

StackOverflow, mailing list activity as of 08/12/14

Page 146: Node.js vs Play Framework (with Japanese subtitles)

88,000 packages in NPM ~80 Play Modules

Page 147: Node.js vs Play Framework (with Japanese subtitles)

88,000 packages in NPM 83,000 artifacts in Maven

Page 148: Node.js vs Play Framework (with Japanese subtitles)

Joyent offers commercial support for Node.js

Typesafe offers commercial support for Play

有償サポート

Page 151: Node.js vs Play Framework (with Japanese subtitles)

49LinkedIn1,172

Indeed3,605 179

CareerBuilder214 16

Open jobs as of 08/13/14採用募集数

Page 152: Node.js vs Play Framework (with Japanese subtitles)

9,037LinkedIn82,698

Indeed2,267 206

CareerBuilder447 30

Candidates as of 08/13/14採用候補者数

Page 153: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8 7

10

10

10

10

3 8

10 7

Page 154: Node.js vs Play Framework (with Japanese subtitles)

Learn

Develop

Test

Secure

Build

The framework scorecard

Deploy

Debug

Scale

Maintain

Share

10 7

8 10

10 10

86

10 7

8 7

10

10

10

10

3 8

10 7

Page 155: Node.js vs Play Framework (with Japanese subtitles)

Final score

85

84

Page 156: Node.js vs Play Framework (with Japanese subtitles)

Final score

85

84

Page 157: Node.js vs Play Framework (with Japanese subtitles)

山田くん、これ全員の座布団全部持って行きなさい!

Page 158: Node.js vs Play Framework (with Japanese subtitles)

Both frameworks are great. Decide based on strengths/weakness, not my arbitrary score!

結論:どちらもすごい!

Page 159: Node.js vs Play Framework (with Japanese subtitles)

1. You’re building small apps with small teams

2. You already have a bunch of JavaScript ninjas

3. Your app is mostly client-side JavaScript

4. Your app is mostly real-time

5. Your app is purely I/O bound

Use node.js if:

向き: 小チーム小アプリ、JavaScript ニンジャ

Page 160: Node.js vs Play Framework (with Japanese subtitles)

1. You don’t write lots of automated tests

2. Your code base or team is going to get huge

3. You do lots of CPU or memory intensive tasks

Don’t use node.js if:

不向き: 自動テスト書かない人、大チーム、高 CPU か 高RAM

Page 161: Node.js vs Play Framework (with Japanese subtitles)

1. You’re already using the JVM

2. You like type safety and functional programming

3. Your code base or team is going to get big

4. You want a full stack framework

5. You need flexibility: non-blocking I/O, blocking I/O, CPU intensive tasks, memory intensive tasks

Use Play if:

向き: JVM ユーザ、型安全性、関数型が好き、大チーム

Page 162: Node.js vs Play Framework (with Japanese subtitles)

1. You don’t have time to master Play, Scala, and SBT

2. You hate functional programming or static typing

Don’t use Play if:

不向き: Play/Scala/sbt を勉強してる時間が無い、型安全性、関数型が嫌い

Page 163: Node.js vs Play Framework (with Japanese subtitles)

Questions?