opa hackathon

72
Hackathon WiFi pass: groundfloorsv Download Opa 1.0.5 at opalang.org while bandwidth lasts

Upload: henri-binsztok

Post on 19-Jun-2015

701 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Opa hackathon

Hackathon

WiFi pass: groundfloorsvDownload Opa 1.0.5 at opalang.org while bandwidth lasts

Page 2: Opa hackathon

Problem #1

Page 3: Opa hackathon

Database

LanguageWeb

Server

Framework

ORM

Memcache

WebServer

WebServer

LanguageLanguage

DatabaseDatabaseDatabaseDatabase

Web BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb BrowserWeb Browser

Web Browser

Web Server

Database

Language

Problem #1

Page 4: Opa hackathon
Page 5: Opa hackathon

Universal Language

Page 6: Opa hackathon

Universal Language

Page 7: Opa hackathon

Universal Language

Page 8: Opa hackathon

Universal Language

Page 9: Opa hackathon

Universal Language

Page 10: Opa hackathon

Problem #2

Page 11: Opa hackathon

> 9 + 5 + “ customers” 14 customers

> “Customers: ” + 9 + 5 Customers: 95

This is JavaScript

Page 12: Opa hackathon

< ?

Page 13: Opa hackathon

if (x == 0)retry();

else if (x == 1)success();

elseerror();

switch (x) { case 0: retry(); break; case 1: success(); break; default: error();}

This is JavaScript

Page 14: Opa hackathon

if (x == 0)retry();

else if (x == 1)success();

elseerror();

switch (x) { case 0: retry(); break; case 1: success(); break; default: error();}

x = “0”

retry error

Page 15: Opa hackathon

This is JavaScript

[] + [] [] + {}{} + [] {} + {}

(@garybernhardt)

Page 16: Opa hackathon

This is JavaScript

[] + [] [] + {}{} + [] {} + {}

= ““= {}= 0= NaN

(@garybernhardt)

Page 17: Opa hackathon
Page 18: Opa hackathon
Page 19: Opa hackathon
Page 20: Opa hackathon
Page 21: Opa hackathon
Page 22: Opa hackathon

Project Launch: June 21st 2011

Man-years: 60+

Page 23: Opa hackathon
Page 24: Opa hackathon
Page 25: Opa hackathon
Page 26: Opa hackathon

Code automation

Page 27: Opa hackathon

Code automation

AJAX/COMET

Non-blocking

Event-driven

Page 28: Opa hackathon
Page 29: Opa hackathon

Code verification

Page 30: Opa hackathon

Code verification

Page 31: Opa hackathon

Code verification

Page 32: Opa hackathon

Live Demo

Page 33: Opa hackathon

JS-like syntax

HTML first class

Event-driven

Page 34: Opa hackathon
Page 35: Opa hackathon

Code verification

Page 36: Opa hackathon

Code verification

Page 37: Opa hackathon

Code verification

Page 38: Opa hackathon

Live Demo

Page 39: Opa hackathon

// try different typing errors:// show errors in the terminal// show type infered

function foo(s) { String.length(s);}

function bar(x, y) { foo(x) + y; // foo("hello") + y; // foo(x) + y + "hello";}

_ = bar("hello", 2)//_ = bar(1, 2)

Live D

emo

To hi

de

Page 40: Opa hackathon

foo = 1 + "bar";

Type checking

“Types int and string are not compatible”

Page 41: Opa hackathon

Type inference

function foo(s) { String.length(s);}

function bar(x, y) { foo(x) + y;}

Page 42: Opa hackathon

Type inference

int function foo(string s) { String.length(s);}

int function bar(string x, int y) { foo(x) + y;}

Page 43: Opa hackathon

Strong static typing without any hassle.

Page 44: Opa hackathon
Page 45: Opa hackathon

A single language

Page 46: Opa hackathon

Client and server

// Will be on server side:function db_update(value) { /mydb/counter <- value}

// Will be on client-side:function dom_update(value) { #counter = value}

Page 47: Opa hackathon

Client and server

function update(value) { /mydb/counter <- value; #counter = value}

Page 48: Opa hackathon

Client and server

function init() { #counter = /mydb/counter}

Page 49: Opa hackathon

Transparent distribution

between client and server

Page 50: Opa hackathon
Page 51: Opa hackathon

Precise control

Page 52: Opa hackathon

Live Demo

Page 53: Opa hackathon

// a dangerous functionprotected function dangerous() { 42 }

// a bit of codefunction code() { dangerous() }

// an innocent bit of client codeclient function malicious() { code() }

Page 54: Opa hackathon

// database operations are protected BY DEFAULT

database mydb { string /personal_data}

function code() { /mydb/personal_data }// Try those different directives:// protected// server -> meaning less

// terminal error without «protected» on codeclient function malicious(code) { code() }

Page 55: Opa hackathon

Precise controlserver

protected

private

client

exposed

asyncsync

public

Page 56: Opa hackathon
Page 57: Opa hackathon

Strong database mapping

Page 58: Opa hackathon

Data declaration

type user = { string mail, int age, list(string) comments}

database dbname @mongo { user /user[{mail}] // primary key int /user/age = 18 // default value}

Page 59: Opa hackathon

Data queries

==!=<<=>>=

in [e1, e2]orandnot

skiplimitorder

/db/col[name == v; order -score; limit 50];

Page 60: Opa hackathon

Data queries/db/col[n > 10 and n < 20];

use db

db.col.find(

{$and : [{ n : { $gt : 10 } },

{ n : { $lt : 20 } } ]

})

opa

mongoDB shell

Page 61: Opa hackathon

Data updates

n += 800n++n--n : v

l popl shiftl <+ el <++ [e1, e2, e3]

/db/path[id == id] <- { n += 1, l <+ e }

Page 62: Opa hackathon

Transparent mapping between db and code values.

Type checking included.

(even for mongoDB)

Page 63: Opa hackathon
Page 64: Opa hackathon

Non-blocking

Page 65: Opa hackathon

function fib(n) { if (n == 0) 0 else if (n == 1) 1 else fib(n-1) + fib(n-2)}

Page 66: Opa hackathon

// Demonstrate a client doesn’t block an other// Several computation at the time are possible// Talk about CPS

import stdlib.themes.bootstrap

// naive fibonaccifunction fib(id, n) { if (n == 0) 0 else if (n == 1) 1 else fib(n-1) + fib(n-2)}

server function action(_) { #result = fib(40)}

function page() { <div class="well"> <button class="btn" onclick={action}>Compute</button> <h2 id=#result class="well" /> </div>}

Server.start( Server.http, { ~page, title: "Hello fibo" })

Live D

emo

To hi

de

Page 67: Opa hackathon
Page 68: Opa hackathon
Page 69: Opa hackathon
Page 70: Opa hackathon

opalang.org@opalang

@henri_opa

Page 71: Opa hackathon

opa create myapp

make run

Page 72: Opa hackathon

Windows: bit.ly/O1JiKc

Linux, Mac: sudo easy_install pip && sudo pip install dotcloud

git clone https://github.com/dotcloud/opa-on-dotcloud

dotcloud create myapp

dotcloud push myapp opa-on-dotcloud