Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Opa hackathon

938 views

Published on

Published in: Technology
  • Be the first to comment

Opa hackathon

  1. 1. HackathonWiFi pass: groundfloorsvDownload Opa 1.0.5 at opalang.orgwhile bandwidth lasts
  2. 2. Problem #1
  3. 3. Problem #1 Memcache FrameworkWeb Browser Web Browser Web Browser Web Browser Web Web Browser Web Web Web Browser Web Browser Server Language Language Web Browser Web Browser Server Server Language Web Browser Language Web Browser Web Browser Web Server Web Browser Web Browser Web Browser Web Browser Web Browser Web Browser Web Browser ORM Web Browser Web Browser Web Browser Web Browser Web Browser Web Browser Database Web Browser Web Browser Database Database Web Browser Web Browser Database Database Web Browser Web Browser Web Browser Web Browser Database Web Browser
  4. 4. Universal Language
  5. 5. Universal Language
  6. 6. Universal Language
  7. 7. Universal Language
  8. 8. Universal Language
  9. 9. Problem #2
  10. 10. This is JavaScript> 9 + 5 + “ customers” 14 customers> “Customers: ” + 9 + 5 Customers: 95
  11. 11. < ?
  12. 12. This is JavaScript switch (x) { case 0:if (x == 0) retry(); retry(); break;else if (x == 1) case 1: success(); success();else break; error(); default: error(); }
  13. 13. x = “0” switch (x) { case 0:if (x == 0) retry(); retry(); break;else if (x == 1) case 1: success(); success();else break; error(); default: error(); } retry error
  14. 14. This is JavaScript [] + [] [] + {} {} + [] {} + {} (@garybernhardt)
  15. 15. This is JavaScript [] + [] = ““ [] + {} = {} {} + [] = 0 {} + {} = NaN (@garybernhardt)
  16. 16. Project Launch: June 21st 2011 Man-years: 60+
  17. 17. Code automation
  18. 18. AJAX/COMETCode automation Non-blocking Event-driven
  19. 19. Code verification
  20. 20. Code verification
  21. 21. Code verification
  22. 22. Live Demo
  23. 23. JS-like syntaxHTML first classEvent-driven
  24. 24. Code verification
  25. 25. Code verification
  26. 26. Code verification
  27. 27. Live Demo
  28. 28. mo De de ive hiL o T // 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)
  29. 29. Type checkingfoo = 1 + "bar"; “Types int and string are not compatible”
  30. 30. Type inferencefunction foo(s) { String.length(s);}function bar(x, y) { foo(x) + y;}
  31. 31. Type inferenceint function foo(string s) { String.length(s);}int function bar(string x, int y) { foo(x) + y;}
  32. 32. Strong static typing without any hassle.
  33. 33. A single language
  34. 34. 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 }
  35. 35. Client and server function update(value) { /mydb/counter <- value; #counter = value }
  36. 36. Client and server function init() { #counter = /mydb/counter }
  37. 37. Transparent distributionbetween client and server
  38. 38. Precise control
  39. 39. Live Demo
  40. 40. // a dangerous functionprotected function dangerous() { 42 }// a bit of codefunction code() { dangerous() }// an innocent bit of client codeclient function malicious() { code() }
  41. 41. // database operations are protected BY DEFAULTdatabase 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() }
  42. 42. Precise control client server exposed protected sync async public private
  43. 43. Strong database mapping
  44. 44. Data declarationtype user = { string mail, int age, list(string) comments}database dbname @mongo { user /user[{mail}] // primary key int /user/age = 18 // default value}
  45. 45. Data queries/db/col[name == v; order -score; limit 50]; == skip in [e1, e2] != limit or < order and <= not > >=
  46. 46. Data queries/db/col[n > 10 and n < 20]; opause dbdb.col.find( {$and : [{ n : { $gt : 10 } }, { n : { $lt : 20 } } ]}) mongoDB shell
  47. 47. Data updates/db/path[id == id] <- { n += 1, l <+ e } n += 800 l pop n++ l shift n-- l <+ e n : v l <++ [e1, e2, e3]
  48. 48. Transparent mapping between db and code values. Type checking included. (even for mongoDB)
  49. 49. Non-blocking
  50. 50. function fib(n) { if (n == 0) 0 else if (n == 1) 1 else fib(n-1) + fib(n-2)}
  51. 51. mo / / D e mo n s t ra te a c li en t d o esn ’ t b l ock an o the r De de / / S e ve r a l c om pu ta ti on at the tim e ar e po s sib le ive hi / / T a lk a b ou t CP SL o T i m po r t s t d li b. th em es .b oot s tra p / / n a iv e f ib on ac ci f u nc t io n f ib (i d, n ) { if (n = = 0 ) 0 el s e i f (n = = 1) 1 el s e f ib ( n - 1) + f ib (n -2 ) } s e rv e r f u n ct io n ac ti on (_) { # re s ul t = f ib (4 0) } f u nc t io n p ag e( ) { <d i v c l a ss =" we ll "> <b u t t on c la ss =" bt n" on c lic k ={a c tio n }>C o mpute</button> <h 2 i d= #r es ul t cl as s=" w ell " /> </ d iv > } S e rv e r. s t a rt ( Se r ve r . h tt p, { ~ pa g e , t it le : "H el lo f ibo " } )
  52. 52. opalang.org @opalang @henri_opa
  53. 53. opa create myapp make run
  54. 54. Windows: bit.ly/O1JiKcLinux, 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

×