AppengineJS is a port of the App Engine Python SDK to JavaScript. While we have taken great pains to closely emulate the Python APIs, given the fact that AppengineJS is actually powered by the App Engine Java SDK, it is difficult to emulate the directory structure of Python Web applications. The developer has to maintain a standard Servlet directory organization, with WEB-INF, web.xml, etc. That's a show-stopper for complexity-averse developers.
Not any more! The latest version of the Java SDK (1.3.5) introduces undocumented support for app.yaml, cron.yaml and the rest of the Python's SDK configuration files. The dev_appserver utility, automatically generates and maintains the WEB-INF directory from these configuration files, making simplified file organizations a reality.
I have updated the standard AppengineJS examples (appengine-example and appengine-blog-example) to demonstrate what is possible with app.yaml. I am sure you will find the updated examples much easier to understand. More information about app.yaml in the Java SDK can be found here.
During the initialization of a Web application, Nitro performs a scan of the src/root directory and constructs a sitemap. The Path middleware leverages this structure to intelligently split incoming request paths to the corresponding scriptName and pathInfo components.
The scriptName component is the path of the JSGI application that will handle the request. If the Render middleware is used, the template path is also derived from scriptName. The pathInfo component stores the extra postfix of the request. Let's use an example to demonstrate the concept:
Given the directory structure (sitemap):
/src/root/articles.js
/src/root/articles/view.js
Nitro automagically splits the request path:
/articles/12339
into:
scriptName: /articles
pathInfo: /12339
since /src/root/articles/12339.js does not exist.
We can use the pathInfo component to implement nice, RESTful URLs... more
Unless you 've been living in a cave for the last year, you know that server side (better: 'general purpose') JavaScript is all the rage. Everything started with CommonJS: the emerging standard spawned an ecosystem of compatible implementations competing against each other while advancing the JavaScript state of the art.
Then, NodeJS happened: An async only JavaScript platform, powered by V8, not really interested in CommonJS conformance. RY (the new DHH) managed to grab the attention of the developer community with cool marketing, leaving other implementations in the shadows. One such great implementation that deserves more attention is RingoJS.
Some time ago I switched from Narwhal to Ringo and never looked back. I strongly believe that Ringo is the preeminent CommonJS implementation. Here is why:
- Ringo is quite possibly the most conformant CommonJS implementation, certainly more conformant than Narwhal and Node.
- Ringo is *fast*. If you tried Narwhal/Rhino and found start up times lacking or module reloading unacceptably slow check out Ringo! You will be pleasantly surprised. And while v8 may be faster than Rhino, the JVM is still quite optimized for server side environments. (And btw, in a modern Web application, time spent running the server side script is a negligible percentage of the total request/response cycle. You should probably work on optimizing network issues, database interactions, client side rendering etc)
- Ringo is mature, stable and crash free. Ringo is the evolution of Helma, one of the first server side JavaScript platforms (more than 10 years in development). It's also based on the mature Java platform. Contrast this to reports of NodeJS crashes.
- Access to the gazillion of Java libraries. There is no merit in reinventing the wheel, just reuse code from the Java ecosystem. The integration between Java and JavaScript is seamless.
- Windows compatibility. OK, Windows sucks, but still, a lot of engineers use Windows as a development platform. Ringo apps work on Windows out of the box.
- Support for synchronous and asynchronous APIs. Use what's best for your application.
- Thanks to AppengineJS you can run your Ringo applications on Google's scalable infrastructure.
- The lead developer is extremely talented and friendly.
Stop drinking the Kool-Aid! Engineer your application on top of a mature, conformant and compatible platform: RingoJS.
Update: Removed a controversial link
As the lead (and lone) developer of an early Rails competitor, I am not particularly fond on DHH & Co. However, there is no denying that good ideas did emerge in the Rails ecosystem. One such idea is the use of inflection to replace configuration with convention.
Some time ago, I needed a simple code generator for one of my projects, thus I looked around for a JavaScript inflection library. After experimenting with a couple of ports of old ActiveSupport code, I decided to implement a subset of the latest ActiveSupport version and package it for CommonJS.
Download the JavaScript inflection library, and try some examples:
var pluralize = require("inflection").pluralize
pluralize("entry"); // "entries"
var singularize = require("inflection").singularize
singularize("words"); // "word"
Yesterday, a post in Hackernews generated considerable interest on AppengineJS, my port of the App Engine Python SDK to JavaScript. The interest was so intense that managed to drain the free quota of the project's site. I guess 'slashdotting' (or should I call this 'newhacking') is the price to pay for the extra publicity.
Some interesting questions were asked in the comments section, so I would like to address some issues and clarify some points:
1. Why use JavaScript instead of Python on App Engine?
If you already know Python, stick to the Python SDK. If you don't want to learn Python and know JavaScript (every single web developer is at least familiar with JavaScript) give AppengineJS a try.
2. Why is JavaScript a great language?
Let the master answer this one:
The World's Most Misunderstood Programming Language
Crockford on JavaScript
Personally, after about 8 years of Ruby programming I don't regret switching to JavaScript. I love the prototypal inheritance, the object literal notation, closures, the C syntax, etc.
3. Why is JavaScript especially suited for Web Applications
Like it or not, JavaScript is the language of the Web just like C is the language of Unix.
The fact that JavaScript is the only language that runs natively on browsers allows you to reuse code across server and client side. And I don't mean just simple form validation code. I use the same template engine at both sides, I use jquery/sizzle at server side for web scraping, I use same jsgi-client code to send http requests at both sides, I use a Canvas-API compatible renderer to generate SVG at server side, I render ajax content at server side for search engine robots and more.
Working exclusively with JavaScript across your app, eliminates the mental context switch required by two separate languages. Oh, did I mention it's much easier to find JavaScript developers (than Python or Ruby developers) for your team?
4. Why does App Engine rock?
Platform as a service changes everything. Of course, App Engine may have the occasional outage or technical problem, but I really dig the fact that Google developers (not my team) are fixing the issue. Quite incredibly, App Engine eliminates the need for system administration, database tuning, security updates, secondary servers setup (email, xmpp, memcache, nginx/apache, squid, etc), etc. When I used Amazon EC2, I almost lost my data twice due to hardware problems on my virtual server. Even though the heroic efforts of the support team saved my ass, I still had to spend a night setting up a new virtual server. There are no servers to fail in App Engine, I love that!
5. Yeah, but isn't Datastore slow?
Datastore is not a relational database, it's a different beast altogether. You have to design your app form scratch with the Datastore in mind. Here are some useful links:
Mastering the datastore
Building Scalable, Complex Apps on App Engine
The Datastore may be slower than, say, MySQL for toy applications (but this can be mitigated through memcache) but the massively distributed, scalable architecture will pay dividends when (eventually) your data explodes.
6. Why not use NodeJS?
Well, NodeJS is a valid, if over hyped, solution. But it only helps you come up with a toy application. With 'toy' I mean an application that runs on your laptop or your staging server. For a production app you need deployment processes, multi version processes, system setup, server tuning, database scaling, backup processes, security policies, monitoring, profiling, admin console etc, etc. App Engine is the easiest way to go from toy to production (though Heroku-Node may provide a viable alternative).
Be open minded and give AppengineJS a try, you may like what you 'll see.
Well, the first day of Google I/O turned out to be better than expected! Especially on the App Engine front there are some extremely positive surprises:
To tell you the truth, given the latest developments in the AWS world, I was afraid that I 've bet on the wrong horse. NOT any more!
In Google we trust!
I 'm not in the mood for a long post, so here are random thoughts in aggregate form:
f8
The new Facebook Social Plugins are FriendConnect done right. FriendConnect has so much potential yet the current implementation leaves a lot to be desired (to say the least). Moreover, the Graph/OpenGraph APIs are a bold step forward towards the machine readable Web (Web 3.0 / Semantic Web if you will). The 'Like' button is an obvious (yet powerful) idea that Google should have implemented a long time ago.
π is wrong
I always thought that 'π' should be the number known as '2π'. Then 'π' would be the perimeter of the unit circle, angle measurements would be more intuitive (90 degrees == π/4, 180 degrees == π/2, 360 degrees = π, ie a full 'cycle' is π radians) and a lot of formulas would be simplified:
p = πr, ie scale the unit perimeter by the radius,
sin(x+π) = sin(x), ie the period of the trigonometric functions is π,
etc. At the moment π is the sum of the angles in a triangle and the perimeter of a circle of with a diameter equal to 1 (doesn't this look awkward to you?). Read 'π is wrong' for a better treatment of the argument.
iPhoneOS TOS
The latest iPhoneOS TOS made a lot of developers angry. I don't agree. One of the problems in our profession is what I call a Babel situation: So many different languages and platforms hinder cooperation. Finding and integrating engineers into a software development team is a pain. Thus, having a single platform (iPhoneOS), a single system language (Objective C) and single scripting/application language (JavaScript) is refreshing.
About a year ago, I switched from AWS to Google App Engine (GAE). To be frank, GAE is a beta quality service, in stark contrast with the mature and elegantly designed Amazon offering. On the other hand, GAE is a higher level service with a killer benefit: it renders system administration obsolete! The are no servers to administrate, no network connections to monitor, no extra services (mail, image processing, backup, etc) to setup and you certainly don't need a DBA to scale the Datastore. Horizontal scaling is automatically catered for and deployment is a no-brainer.
Still, this service needs a lot of improvement. Here are some features I would like to see, sooner rather than later:
Firewall API
The API should allow for easy blocking of dos attacks and restricting access to annoying users and wild robots.
Full Text Search
Come on, this is Google!
Map Reduce
Again, this is Google. Map Reduce is totally required in NoSQL environments (like Datastore).
Asynchronous Datastore calls
Async URLFetch is a great first step, but async Datastore calls would dramatically improve the performance of typical applications.
Support for Servlet 3.0 async model
End to end support for async would allow for implementation of NodeJS-style frameworks on top of GAE.
Blobstore API improvements
This API seems half-baked at the moment. I would like to see a more intuitive, S3-like interface. Better integration with the Image API and support for ETags would be desirable.
Release the source code of the Java SDK
Google already releases the source code of the Python SDK. Releasing the source code of the Java SDK would be extremely helpful for developers of alternative language SDKs (like AppEngineJS).
Multitenancy
Support for multitenancy in the Datastore would trigger an explosion of Web applications on the platform. Moreover, an improved Google Apps Marketplace would be a catalyst in the creation of a viable ecosystem.
I read this post on Signal vs Noise with great interest. Ryan correctly identifies the problems with local variable declaration in Erb templates and offers a clever Ruby hack as a solution:
<% message.comments.last.tap do |comment| %>
<li><%= comment.creator %></li>
<% end %>
While .tap() introduces a scope it still smells as bad style. A more fundamental flaw lies underneath: the lack of true separation of data and presentation. Consider the following alternative using Normal Templates:
{:reduce comments}
<li>{=creator}</li>
{/:reduce}
or the equivalent shorter version: more
OK, I am sold, Google's social stream app just rocks! The Internet is ..buzzing with rave reviews and really what is there not to like: no lame 160 char limitation, in-line media support, integration with GMail, recommendation and filtering algorithms, auto discovery of the social graph, etc. All packaged with an intuitive user interface.
But the real benefit is the use of Open Standards. New York Times nailed this perfectly:
Google Buzz data can be syndicated out to other services using the standard data formats called Atom, Activity Streams, MediaRSS and PubSubHubbub. That couldn't be more different from Facebook. Google has taken open data standards to battle against a marketplace of competitors that are closed and proprietary to varying degrees. This is a very big deal.
Compare this to Facebook's closed garden and Twitter's ad-hoc (and badly designed/integrated) APIs. Just reuse your ATOM parser, leverage Pubsubhubbub's webhook model and you are off. more