jslab.Руслан Шевченко."javascript как платформа...

28
JS as PL Platform review of languages, evaluated in JS Ruslan Shevchenko //lynx capital partners @rssh1

Upload: geekslab

Post on 15-Jul-2015

140 views

Category:

Technology


1 download

TRANSCRIPT

JS as PL Platformreview of languages, evaluated in JS

Ruslan Shevchenko//lynx capital partners

@rssh1

JS Languages• Why ?

• Better JavaScript (types, async, etc .. )

• Language ecosystems (C, Scala, Clojure)

• Explore ideas (tier-programming, CoP )

• Because I can ;)))

CoffescriptDart

TypeScript

Traceur

Emscripten(C, C++, Rust)

Scala.js

Clojure-Script KotlinJava (gwt, applets)

Gopher.js

IdrisOpa

Ur/web

Asm.js

Shen

Coffeescript• http://coffeescript.org/

• javascript with classes + ruby-inspired syntax

• actually used in industry

• literate programming [markdown syntax]

• syntax sugar [ =>, tuple assignment, expr.]

• “javascript + goodies from modern dynamic language”.

Dart / TypescriptGoogle Microsoft

Class semantics + optional typing

trait/mixingeneric

syntax sugar, this scopingasync/await in process

interfaces [structural typing]

Traceur

• https://github.com/google/traceur-compiler

• Google

• JS [6, 7] + optional types/annotations => Js - now

• [async, async generator, =>, … , etc]

Async functionfunction t1(x) { return new Promise(….) }

async function f2(x) { await t1(10); return x2 }

async function f3(x) { x1 = await t(10); x2 = await f2(x1) doSomething }

function f3(x) { f(function() { f2(function(x2) { doSomething } } }

// simplified. (without error handling)

escape callback hell

Async generatorfunction* asyncGen(x) { for(i in items) { yield new Promise(….) } }

// simplified. (without error handling)

async function useGen() { for(i on asyncGen(x)) { … do-something } }

Async• Other implementations:

• https://github.com/yortus/asyncawait (node-fibers)

• http://routines.ch/ (go-like channels)

• https://github.com/benjamn/es7-async-await (es7 => es6)

• https://github.com/facebook/regenerator (es7 => es5)

asm.js

• http://asm.js

• Grown from mozilla research project. Supported now by all major browsers [FF, chrome, next MS, Opera]

• Subset of javascript.

• Types are set with ‘annotation operations'

asm.jsfunction AsmModule { use “asm”;

function f(x,y) { x=x|0; // x is int. y = +y; // y is double return + (y/(x+1)); // double }

return { f: f } }

asm.jsfunction AsmModule { use “asm”;

function f(x,y) { x=x|0; // x is int. y = +y; // y is double return + (y/(x+1)); // double }

return { f: f } }

- Compile to low-level efficient code (if typechecked)

- low-level performance-critical code

- for compilers / interpreters (not people)

Emscripten

• http://kripken.github.io/emscripten-site/

• C, C++ => LLVM => Asm.js

• (near native speed, OpenGL support).

• // RUST support is underway.

Emscripten• C, C++ ecosystem:

• curses: https://github.com/coolwanglu/PDCurses.js

• example: http://coolwanglu.github.io/PDCurses.js/xmas.html

• vi: https://github.com/coolwanglu/vim.js

• just s/gcc/emcc/ in Makefile ;)

Emscriptenexample: vi port

Emscripten• More useful use-cases:

• Games:

• Unity 4 provide asm.js generation.

• UnrealEngine

• DosBox works perfectly

• Math: Image recognition in browser

Notables ecosystems• Scala:

• scala.js: http://www.scala-js.org/ (full compiler)

• lightweight jscala macro (made in Kiev by @atlanter)

• Clojure: clojure-script: https://github.com/clojure/clojurescript

• Java: http://www.gwtproject.org/overview.html

• On the way:

• Erlang [Shen]: https://github.com/synrc/shen ( made in Kiev by @5HT )

• Go [Gopher.js]: https://github.com/gopherjs/gopherjs

Scala-JS

• Scala-compiler + sbt plugin. (familiar build tool to scala developers)

• Support of javascript dependencies (WebJars)

• Typed binding to most notable JS libs

• Ports for of reactive extensions, akka

Scala-js

• Scala goodies, extremely useful:

• ADT (case classes)

• macroses [async/await work out of the box]

• typeclasses

Clojure-Script

• Clojure-compiler + lein plugin. (familiar build tool to clojure developers)

• Support of javascript dependencies (CloJars)

• OM/React framework is ‘mainstream’ in ‘non-mainstream world’.

Kotlin• http://kotlinlang.org/

• Main Idea: ‘better java’ from jet-brains

• karra - web framework

• statistically typed CSS

• DSL for html

ol { li("List Item 1") li("List Item 2") } fieldset() { label("Text Input") input(inputType="text", value="Text") }

JS-backed architectures:

• tier-less language

• compiler will decide, where run you code:

• frontend, backend, db…

• language-integrated persistency and forms

JS-backed architectures:

• OPA: http://opalang.org/

• frontend: browser,

• backend: node.js

• persistency: mongo-db

• Language: like ML with { } syntax

JS-backed architectures:• Ur/Web: http://www.impredicative.com/ur/

• frontend: browser,

• backend: own server

• persistency: SQL binding to language types

• Language: like ML with Haskell typicalness

• Exists commercial applications.

CoffescriptDart

TypeScript

Traceur

Emscripten(C, C++, Rust)

Scala.js

Clojure-Script KotlinJava (gwt, applets)

Gopher.js

IdrisOpa

Ur/web

Asm.js

Shen

Js-languages• Resume, if you still want be in ‘mainstream’ JS

world:

• Static type checker [flow: http://flowtype.org/ ]

• Async [multiple implementations]

• Get used to live with this scope :(

• may-be macroses [ http://sweetjs.org/ ]

Thanks for attention

• Ruslan Shevchenko.

• https://github.com/rssh

• @rssh1