24
http://opalang.org @henri_opa

Opa presentation at GamesJs

Embed Size (px)

Citation preview

Page 2: Opa presentation at GamesJs
Page 3: Opa presentation at GamesJs

open-sourceevent-based

client + server

Page 4: Opa presentation at GamesJs

#1 Simple

Page 5: Opa presentation at GamesJs

function register_in_the_room() {join(nick); onConnect();

}

function get_list_of_users() {users = get_user_list(); showUsers(users);

}

function register_in_the_room() {$.ajax({

cache: false, type: "POST" , dataType: "json" , url: "/join" , data: { nick: nick } , error: function () {

alert("connection error”); showConnect();

} , success: onConnect

});}

function get_list_of_users() {jQuery.get("/who", {},function (data, status) {

if (status != "success") return; showUsers(data.nicks);

}, "json");}

Page 6: Opa presentation at GamesJs
Page 8: Opa presentation at GamesJs

http://github.com/mattgu74/OpaTetris

600

Page 9: Opa presentation at GamesJs
Page 10: Opa presentation at GamesJs

1100

Page 11: Opa presentation at GamesJs

#2Cool static

typing

Page 12: Opa presentation at GamesJs

Type errors atcompile time? Yes

No

Error

function createUser(username, password) {

match (findUser(username)) {

case {none}: user =

{ username: username,

fullname: "",

password: Crypto.Hash.sha2

(password) }; saveUser(user);

default: displayMessage(“This username

exists”);

};

Client.goto("/login");

Code

Page 13: Opa presentation at GamesJs

Type checking

foo = 1 + "bar";“Types int and string are

not compatible”

Page 14: Opa presentation at GamesJs

Type inference(almost complete)

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

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

Page 15: Opa presentation at GamesJs

Type inference(almost complete)

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

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

Page 16: Opa presentation at GamesJs

element = <div> <span>{prompt({none})}</span> <span>{expr} </div> <div>{Calc.compute(expr)}</div>;

Open and close tag mismatch <span> vs </div>

Page 17: Opa presentation at GamesJs

case {some: 13}: #status = "Enter"; callback(get());case {some: 37}: #status = "Left"; move({lef});case {some: 38}: #status = "Up"; move({up});case {some: 39}: #status = "Right"; move({right});

First type: { lef }Second type:

{ left } or { right } or { rightmost } or { up } or { down }

Page 18: Opa presentation at GamesJs

previous = Dom.get_content(#precaret);#precaret = String.sub(0, String.lenght(previous) - 1, previous);#postcaret += String.get(String.length(previous) - 1, previous);

No field ‘lenght’ found.Most probable field:length: string -> int

Page 19: Opa presentation at GamesJs

previous = Dom.get_content(#postcaret);#postcaret = String.sub(1, String.length(previous) - 1, previous);#precaret =+ String.get(previous);

String.get is a string function(int, string) but

application uses itas function(string)

Page 20: Opa presentation at GamesJs
Page 21: Opa presentation at GamesJs
Page 22: Opa presentation at GamesJs

“Keep your eye on Opa, the new open source language that [...] may transform Web development.”

“Coding in Opa is super quick and fun. I don’t think I could have written things faster in any other framework.” Alok Menghrajani

Neil McAllister

Page 23: Opa presentation at GamesJs

Join device: Tokyo

http://tokyo.local:8667

Page 24: Opa presentation at GamesJs

opalang.org@opalang