The perfect Javascript framework

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

Interesting:

We all like simple tools. Complexity kills. It makes our work difficult and gives us much steeper learning curve. Programmers need to know how things work. Otherwise, they feel insecure. If we work with a complex system, then we have a big gap between “I am using it” and “I know how it works”. For example, code like this hides complexity:

var page = Framework.createPage({
‘type’: ‘home’,
‘visible’: true
});

Let’s say that this is a real framework. Behind the scenes, createPage generates a new view class that loads the home.html template. Based on the visible parameter we append (or not) the newly created DOM element to the tree. Now, let’s put ourselves in the developer’s shoes. We read in the documentation that this creates a new page with a certain template. We do not know any particular details because this is an abstraction.

Some of today’s frameworks have not one, but many levels of abstractions. Sometimes, in order to use the framework properly, we have to know the details. Abstracting, in fact, is a powerful instrument because it wraps functionalities. It encapsulates design decisions. However, it should be used wisely because it leads to untraceable processes.

What if we transform the above example to the following:

var page = Framework.createPage();
page
.loadTemplate(‘home.html’)
.appendToDOM();

Now the developer knows what is going on. The template and the appending are exposed to different API methods. So, he/she can do something in between and control the processes.

Post external references

  1. 1
    https://dev.opera.com/articles/perfect-javascript-framework/
Source