сряда, 13 март 2013 г.

JavaScript Alternatives


This is a short list of alternative languages of JavaScript:

1. Dart was unveiled at the GOTO conference in Aarhus in October 2011 October. It was developed at Google. Its goal is to replace JavaScript as the lingua franca of web development on the open web platform. Dart is intended to address JavaScript's problems, which, cannot be solved by evolving the language, while offering better performance, the ability to be more easily tooled for large-scale projects and better security features.

2. CoffeeScript is a programming language that transcompiles to JavaScript. The language is inspired by Ruby, Python and Haskell to enhance JavaScript's brevity and readability, and add more sophisticated features like list comprehension and pattern matching. CoffeeScript compiles predictably to JavaScript and programs can be written with less code. Critisims of CoffeeScript is that it does not bring any new paradigm and that's why it is unnecessary.

събота, 9 март 2013 г.

Static Resources with node.js and express


To use static resources with node.js and the express framework you should put all your code in a folder "static" and tell node.js to serve the static pages:

app.use(express.static('static'));

My First backbone.js experiment

The recommended way to use backbone.js for a website is to use some framework. Here is my first most basic test that I have posted on Heroku.
var util = require('util');

var express = require('express');
var app = express();

var port = 3000;

app.use(express.static('static'));
app.get('/', function(req, res) {
    res.send('<link rel="stylesheet" type="text/css" href="stylesheets/basic.css"></link>'
             + '<div class="game title"><h1>Hello from Me</h1></div>'
             + '<a href="http://appworld.blackberry.com/webstore/vendor/31055/">'
             + '<img src="imagery/bbappworld_getitat_english_white.jpg" alt="Get it at BlackBerryWorld Logo"/>')
             + '</a>';
});

app.listen(port);
util.puts('Listening on ' + port + '...');
util.puts('Press Ctrl + C to stop!');
This code uses the express framwork.

Node.js - JavaScript on the Server

After I have explored several cloud solutions and frameworks I have met Node.js. It is hosted by such cloud solutions as:
You can find Node.js at
Free tutorials are available:
I will be updating this blog as soon as I come across more resources.

Backbone.js resources

Here are links to various Backbone.js tutorials:

Sample applications:
I will be updating this post with more resources when I come across them.

Organizing Your Code

When programming web applications sometimes it is best to use Single-page Applications (SPA). This is a new practice. It is not SEO friendly thus you need to be extra careful, when creating SPA websites.
A recommended way to develop SPAs is to use a framework. Various frameworks are available. A simple and popular solution is: backbone.js

 Backbone.js offers a lean MVC framework for organizing your Javascript application. It leads to more maintainable code by untangling the "spaghetti" of callbacks tied to different parts of the DOM and the backend server that often arises in rich client-side applications.


Namespaces


JavaSript lacks built-in support for namespaces. Namespaces are essential in organizing your code. One way to simulate namespaces would be: 
if (!window.com) com = {};
if (!com.mynamespace) com.mynamespace= {};
if (!com.mynamespace.subnamespace) com.mynamespace.subnamespace= {};
And then you can add to it:
com.mynamespace.subnamespace.myFunction = function(){
    // Do something
};