opa presentation at gamesjs
TRANSCRIPT
http://opalang.org
@henri_opa
open-sourceevent-based
client + server
#1 Simple
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");}
http://github.com/mattgu74/OpaTetris
http://github.com/mattgu74/OpaTetris
600
1100
#2Cool static
typing
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
Type checking
foo = 1 + "bar";“Types int and string are
not compatible”
Type inference(almost complete)
function foo(s) { String.length(s);}
function bar(x, y) { foo(x) + y;}
Type inference(almost complete)
int function foo(string s) { String.length(s);}
int function bar(string x, int y) { foo(x) + y;}
element = <div> <span>{prompt({none})}</span> <span>{expr} </div> <div>{Calc.compute(expr)}</div>;
Open and close tag mismatch <span> vs </div>
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 }
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
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)
“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
opalang.org@opalang