opa hackathon

Post on 19-Jun-2015

701 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Hackathon

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

Problem #1

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

Universal Language

Universal Language

Universal Language

Universal Language

Universal Language

Problem #2

> 9 + 5 + “ customers” 14 customers

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

This is JavaScript

< ?

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

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

This is JavaScript

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

(@garybernhardt)

This is JavaScript

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

= ““= {}= 0= NaN

(@garybernhardt)

Project Launch: June 21st 2011

Man-years: 60+

Code automation

Code automation

AJAX/COMET

Non-blocking

Event-driven

Code verification

Code verification

Code verification

Live Demo

JS-like syntax

HTML first class

Event-driven

Code verification

Code verification

Code verification

Live Demo

// 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

foo = 1 + "bar";

Type checking

“Types int and string are not compatible”

Type inference

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

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

Type inference

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

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

Strong static typing without any hassle.

A single language

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}

Client and server

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

Client and server

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

Transparent distribution

between client and server

Precise control

Live Demo

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

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

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

// 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() }

Precise controlserver

protected

private

client

exposed

asyncsync

public

Strong database mapping

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}

Data queries

==!=<<=>>=

in [e1, e2]orandnot

skiplimitorder

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

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

use db

db.col.find(

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

{ n : { $lt : 20 } } ]

})

opa

mongoDB shell

Data updates

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

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

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

Transparent mapping between db and code values.

Type checking included.

(even for mongoDB)

Non-blocking

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

// 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

opalang.org@opalang

@henri_opa

opa create myapp

make run

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

top related