aries: What’s next

In recently released framework I had done a lot of magic. One of most important part is magic done with  ClassLoader. Although I enjoy the simplicity provided by Node.js dependency handling (require stuff) It  forces to use special syntaxis that definitely won’t work on client side without special wrappers.

And I guess it is possible to do really awesome things like auto dependancies resolving, code modification, annotations and maybe even more. Currently in aries  annotation handling is done by jsSourceCodeParser. It is ok but limited since mostly done with regexp parsing which is not reliable enough to provide solid ground for framework.

And here codesurgeon  was released just recently. After checking the implementation I had finally found javascript parser I look for a long time (seems not hard enough though) uglify-js parser.

So now I am focused to do massive refactorings in ClassLoader that will allow to do so much magic and help boost server side JavaScript any way developer want in a runtime.

 

Posted in post | Leave a comment

aries release

I want to officially announce 0.0.1 release of aries mvc framework for nodejs.

github repository

project site

let’s start from hello-world app:

/**
 *@RequestMapping(value="/hello-world")
 */
HalloWorldController.prototype.sayHello =
                               function(request, response){
	response.end("Hello world!");
};

As you can see url routing is done with simple annotations. I have think that annotations are awesome and hope there are people who will like that style of coding.

You can check more examples on official site and start shortly.

next post will be on what comes next

Posted in post | Tagged , | Leave a comment

Few quotes from Quora about Node.js

Ryan Grove, YUI engineer at Yahoo!

Node.js showed up at the right time. PHP, currently the most popular server-side language, has been mired in community squabbling amidst a large effort to refactor its character encoding support, while also losing developer mindshare to the many excellent Ruby web frameworks that have appeared in the last few years. But Ruby web frameworks, and the language itself, have become notorious for having performance issues and sometimes being hard to scale (although some of this perception is based on misinformation), so the appearance of a new highly performant, highly scalable evented IO framework built on top of the world’s most popular programming language couldn’t have been better timed.

Assaf Arkin, http://labnotes.org

Ruby is a great language, you can do functional programming with it, you can do asynchronous/evented, and you can do objects right. But it doesn’t come easy, and not all the libraries you use will play along. Quite a lot of libraries are mixed style.

Contrast with JavaScript: it’s functional, evented and has the prototype object model. It was designed that way, and encourages people to develop to that style, which helps you when everything up/down the stack works the same way.

Posted in post | Leave a comment

Nice stuff is happening: CommonJS Package Manager.

Idea of some central plugin/snippet/library directory for javascript floats in the air for a long time. But seems there were no important piece of a puzzle.

Im using Nodejs alot lately. And NPM is really great. The last piece :)

Now we have CPM http://packages.dojofoundation.org/ which I see even more promising since we can use it for both server and client side.

I guess NPM should become industry standart.

Posted in post | Leave a comment

New post everyone!

It’s a long time since last post. I have started at least two different projects and both of them are not finished. I hope to have more free time in 2-3 month.
Im in San Francisco right now and happy to work on new project with Hotwire. It’s a brand new application we start form scratch using Spring-mvc. This is really great experience.
We try to keep things as simple as possible, avoid Ajax and complex javascript on the pages. I think it is wise for mature company.

Posted in post | Leave a comment

JS features you better know 1

In scope of functions arguments is local variable provides some nice features we can use in our code. First you don’t need to define any parameters for a function. You can just use arguments and will get arguments passed to the function.

    function sum(){
        var ret = 0;
        for (var i = 0; i < arguments.length; ++i) {
            ret += arguments[i];
        }
        return ret;
    }

    sum(1, 2, 3) //returns 6

Worth noting though that although we use arguments like an array, it’s not an actual javascript Array — it’s just an object. So you can’t do join(), pop(), push(), slice() and so forth.(You can convert it to a real array if you want: “var argArray = Array.prototype.slice.call(arguments);” )

arguments.callee property refers to the function that is currently running. It provides a way for unnamed function to refer to itself. This allows to make nice recursions:

    function fibonacci(){
        if (arguments.length == 1 && arguments[0] > 2) {
            return arguments.callee(arguments[0] - 2, [0, 1]);
        }
        if (arguments[0] == 0) {
            return arguments[1];
        }
        else {
            var len = arguments[1].length;
            return arguments.callee(arguments[0] - 1, arguments[1].concat(arguments[1][len - 1] + arguments[1][len - 2]));
        }
    }
    fibonacci(7) //returns [0, 1, 1, 2, 3, 5, 8]

Notice that “callee” property allows to do recursion with anonymous functions.

arguments.callee.caller property refers to a method called your function. This could be useful for example if you want to forbid public class creating and allow it for Factory only:

    function MyClass(){
        if (arguments.callee.caller != MyFactory.createObject) {
            throw new Error("There is no public constructor for MyClass.");
        }
        this.myproperty = "hello world";
    }
Posted in post | Tagged , | Leave a comment

“Even Faster Websites”

OReily Even Faster Websites is a great book. It has some Javascript perfomance hints in its “Writing Efficient JavaScript” part. Here are conclusions:

  • Use local variables
  • Avoid with statement
  • do not use too deep properies, redefine them with locals if possible
  • Use the if statement when:
    — There are no more than two discrete values for which to test.
    — There are a large number of values that can be easily separated into ranges.
  • Use the switch statement when:
    — There are more than two but fewer than 10 discrete values for which to test.
    — There are no ranges for conditions because the values are nonlinear.
  • Use array lookup when:
    — There are more than 10 values for which to test.
    — The results of the conditions are single values rather than a number of actions
    to be taken.
  • To improve perfomance of loops decrement the iterator toward 0 rather than incrementing toward the total length.
Posted in post | Leave a comment