AppengineJS

3,305 views

Published on

My presentation on AppengineJS at the Greece Google Technical User Group on March 23rd 2011.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,305
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
20
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

AppengineJS

  1. 1. AppengineJS JavaScript on Google App Engine
  2. 2. Why JavaScript? <ul><ul><li>The World's Most Popular Programming Language </li></ul></ul><ul><ul><li>The World's Most Misunderstood Programming Language </li></ul></ul><ul><ul><li>Dynamic, Functional, Prototypal (not Java!) </li></ul></ul><ul><ul><li>Event loop instead of threads </li></ul></ul><ul><ul><li>Engine explosion: v8, Nitro, SpiderMonkey, Rhino, Chakra, Carakan </li></ul></ul><ul><ul><li>JavaScript on the server: Node, Helma/Ringo, Narwhal, Persevere, Jaxer, Joyent Smart, GPSEE and many others </li></ul></ul>
  3. 3. Standardization <ul><ul><li>Common API for JavaScript applications </li></ul></ul><ul><ul><li>Analogous to stdlib/stdio </li></ul></ul><ul><ul><li>Implementations exist for most engines </li></ul></ul><ul><ul><li>Specifications: modules, packages, system, binary, encodings, filesystem, console, promises, testing and more  </li></ul></ul><ul><ul><li>http://commonjs.org/ </li></ul></ul>
  4. 4. Script in JavaScript <ul><li>var File = require( &quot;fs&quot; ); </li></ul><ul><li>var csv = File.open( &quot;invitations.csv&quot; ); </li></ul><ul><li>var out = File.open( &quot;invitations2.csv&quot; , &quot;w&quot; ); </li></ul><ul><li>for ( var i = 1; i<33421; i++) { </li></ul><ul><li>     var line = csv.readLine(); </li></ul><ul><li>     var comma = line.indexOf( ',' ); </li></ul><ul><li>     var newline = '&quot;' + i + '&quot;' + line.substring(comma); </li></ul><ul><li>     out.write(newline); </li></ul><ul><li>} </li></ul><ul><li>out.flush(); </li></ul>
  5. 5. Smash hit <ul><ul><li>Evented non-blocking I/O server </li></ul></ul><ul><ul><li>Every API rewritten from scratch as async </li></ul></ul><ul><ul><li>JavaScript is perfect for event loop architectures </li></ul></ul><ul><ul><li>Uses v8, the fastest engine </li></ul></ul><ul><ul><li>http://nodejs.org </li></ul></ul>
  6. 6. Google App Engine <ul><ul><li>Run your web apps on Google's infrastructure </li></ul></ul><ul><ul><li>Excellent scalability </li></ul></ul><ul><ul><li>Free for low traffic apps </li></ul></ul><ul><ul><li>Zero admin </li></ul></ul><ul><ul><li>Officially supported languages: Python, Java </li></ul></ul><ul><ul><li>Unofficial implementations: Clojure, PHP, Groovy, JavaScript </li></ul></ul><ul><ul><li>http://code.google.com/appengine/ </li></ul></ul>
  7. 7. AppengineJS stack
  8. 8. Rhino
  9. 9. Rhino <ul><ul><li>JavaScript for Java </li></ul></ul><ul><ul><li>Works both ways </li></ul></ul><ul><ul><li>Ships with the default JDK </li></ul></ul><ul><ul><li>Used to be the fastest JavaScript VM </li></ul></ul><ul><ul><li>Still very performant for long-running processes </li></ul></ul><ul><ul><li>Renewed focus with JSR-292 </li></ul></ul><ul><ul><li>With Mozilla extensions and most of ECMAScript5 </li></ul></ul><ul><ul><li>http://www.mozilla.org/rhino/ </li></ul></ul><ul><li>  </li></ul>
  10. 10. Narwhal
  11. 11. Narwhal <ul><ul><li>General purpose JavaScript platform </li></ul></ul><ul><ul><li>Runs on various JavaScript engines (Rhino, Nitro) </li></ul></ul><ul><ul><li>Large collection of packages </li></ul></ul><ul><ul><li>CommonJS compliance </li></ul></ul><ul><ul><li>http://narwhaljs.org/ </li></ul></ul>
  12. 12. Ringo
  13. 13. Ringo <ul><ul><li>Descendant of Helma </li></ul></ul><ul><ul><li>Adds on top of Rhino: </li></ul></ul><ul><ul><ul><li>A fast, auto-reloading, CommonJS module loader </li></ul></ul></ul><ul><ul><ul><li>Modules covering I/O, logging, persistence </li></ul></ul></ul><ul><ul><ul><li>Jetty-based HTTP server and client </li></ul></ul></ul><ul><ul><ul><li>CommonJS packages support </li></ul></ul></ul><ul><ul><li>Graphical debugger </li></ul></ul><ul><ul><li>High-level web framework </li></ul></ul><ul><ul><li>http://ringojs.org/ </li></ul></ul>
  14. 14. JSGI/Jack
  15. 15. Jack/JSGI <ul><ul><li>JSGI is a web server interface specification for JavaScript   </li></ul></ul><ul><ul><li>Jack is the first implementation </li></ul></ul><ul><ul><li>Similar to Ruby's Rack and Python's WSGI </li></ul></ul><ul><ul><li>Simpler than Java Servlets </li></ul></ul><ul><ul><li>http://jackjs.org/ </li></ul></ul>
  16. 16. Hello World <ul><li>function (env) { </li></ul><ul><li>   return { </li></ul><ul><li>     status : 200, </li></ul><ul><li>     headers : { &quot;Content-Type&quot; : &quot;text/plain&quot; }, </li></ul><ul><li>     body : [ &quot;Hello world!&quot; ] </li></ul><ul><li>   }; </li></ul><ul><li>} </li></ul>
  17. 17. AppengineJS
  18. 18. AppengineJS <ul><ul><li>Created by George Moschovitis (@gmosx) </li></ul></ul><ul><ul><li>Available APIs: </li></ul></ul><ul><ul><ul><li>Datastore </li></ul></ul></ul><ul><ul><ul><li>Memcache </li></ul></ul></ul><ul><ul><ul><li>Multitenancy (Namespace manager) </li></ul></ul></ul><ul><ul><ul><li>URL Fetch </li></ul></ul></ul><ul><ul><ul><li>Mail </li></ul></ul></ul><ul><ul><ul><li>XMPP </li></ul></ul></ul><ul><ul><ul><li>Images </li></ul></ul></ul><ul><ul><ul><li>Users </li></ul></ul></ul><ul><ul><ul><li>OAuth </li></ul></ul></ul><ul><ul><ul><li>Task Queue </li></ul></ul></ul><ul><ul><ul><li>Blobstore </li></ul></ul></ul><ul><ul><ul><li>Quota </li></ul></ul></ul><ul><ul><ul><li>Local Unit Testing </li></ul></ul></ul>
  19. 19. Memcache <ul><li>var mc = require( &quot;google/appengine/api/memcache&quot; ); var fragment = mc.get( &quot;fragment&quot; ); if (!fragment) {   // generate fragment   mc.set( &quot;fragment&quot; , fragment); } </li></ul>
  20. 20. Datastore <ul><li>var db = require( &quot;google/appengine/ext/db&quot; ); var Category = db.Model( &quot;Category&quot; , {   label: new db.StringProperty(),   category: new db.ReferenceProperty({referenceClass: Category}) }); var c = new Category({keyName: &quot;news&quot; , label: &quot;News&quot; }); c.put(); var key = ... var c1 = Category.get(key); var c2 = Category.getByKeyName( &quot;news&quot; ); var categories = Category.all().fetch(3); ... var comments = Comment.all().ancestor(article).order( &quot;-created&quot; ).withCursor(cursor).fetch(10); </li></ul>
  21. 21. Nitro
  22. 22. Nitro <ul><ul><li>A collection of CommonJS packages instead of a monolithic framework: </li></ul></ul><ul><ul><ul><li>AppengineJS </li></ul></ul></ul><ul><ul><ul><li>Normal Template  - client/server-side templating </li></ul></ul></ul><ul><ul><ul><li>HTMLParser  - jQuery-compatible HTML5 parser </li></ul></ul></ul><ul><ul><ul><li>Markdown </li></ul></ul></ul><ul><ul><ul><li>Inflection  - Rails/ActiveSupport inflector </li></ul></ul></ul>
  23. 23. HTMLParser <ul><li>var HTMLParser = require( &quot;htmlparser&quot; ).HTMLParser, </li></ul><ul><li>   sizzle = require( &quot;sizzle&quot; ).sizzle; </li></ul><ul><li>var html = '<html><p id=&quot;header&quot;><b>nice</b></p><div id=&quot;test&quot; class=&quot;big&quot;>hello</div><div>second</div></html>' , </li></ul><ul><li>   parser = new HTMLParser(), </li></ul><ul><li>   document = parser.parse(html), </li></ul><ul><li>   $ = sizzle(document); </li></ul><ul><li>$( &quot;div&quot; ).forEach(function(el) { </li></ul><ul><li>   print(el.innerHTML); </li></ul><ul><li>}); </li></ul><ul><li>print(document.toHTML()); </li></ul><ul><li>print(document); </li></ul>
  24. 24. Q&A <ul><li>AppengineJS: </li></ul><ul><li>http://www.appenginejs.org </li></ul><ul><li>Nitro: </li></ul><ul><li>http://www.nitrojs.org </li></ul><ul><li>Blog example downloads: </li></ul><ul><li>http://tinyurl.com/appenginejs-sdk </li></ul><ul><li>http://tinyurl.com/appenginejs-example </li></ul><ul><li>This presentation: </li></ul><ul><li>http://tinyurl.com/appenginejs-talk </li></ul><ul><li>Panagiotis Astithas  (@pastith) </li></ul>

×