Joose blog

Blog about Joose – advanced class system for JavaScript

Archive for the ‘Advocacy’ tag

Why Joose? Part #2 (phylosophical)

with 3 comments

If the the previous (practical) answer on the question “Why Joose?” doesn’t sounds convincing for you, here is the philosophical (aka meta-physical) variant. Yes, we like the “meta” word :)

Abstraction layers

Lets start with the following – why we all are programming anyway? Obviously to solve some real-world tasks. And we solve them, by translating the behavior of real-world systems into machine code. Such translation can’t be direct yet, as the computers are presently “dumb” and it has to be performed in the layered fashion.

That is, the first, outermost abstraction layer is the “user story”, written in the natural human language by the end-users.

The further level will probably be a technical specification, written by software analyst, or (in the agile methodology) a set of tests, representing the data-domain knowledge in the programmer’s head.

Yet another level will be the actual program, most probably written in some high-level language like JavaScript, Perl or Java (we treat everything except the assembler as high-level language here).

There will be also a byte-code layer, etc, the chain ends at the actual bits dancing on the silicon chips.


Ok, now lets take a look from another (quite abstract) side. That real world task can be characterized by its “complexity”. This term is somewhat close to the “entropy”, may be its even a synonym.

We can say that each abstraction layer, we’ve used during translation, absorbs some part of that complexity. Like the sponge.

To solve the task, it’s whole complexity should be absorbed. You can’t leave some of it un-absorbed, as that will just means that some aspects of the system weren’t addressed.

So, the whole point is that, if you’ll be used “poorly absorbing” layers as tools, you’ll have to absorb the remaining complexity somewhere else, either in the code or in your head :)


Imagine you need to analyze some text file and extract repeating patterns from it, using C/C++ string manipulation capabilities. Compare with the same task for Perl/JavaScript style regular expressions.

Imagine you need to write the image recognition program in assembler.

Imagine you need to refactor the complex system and you don’t have the full and complete test suite (outer abstraction layer). Compare with the same task, when you have it. This is an example of poorly absorbed complexity.

Compare the implementations of quicksort algorithm in C and Haskell: This is an example of layers with different absorbing capabilities.


So what’s special about the Joose and complexity? Its that Joose has meta-layer, which allows you to modify the behavior of your code (not the system being modeled).

And, modifying the behavior of the code, you can absorb any boilerplate you usually had to write. Moreover, you don’t just reduce the number of lines, you free your mind from that boilerplate. For example, consider this common pattern:

getSomething : function () {
    if (typeof this.something == 'undefined') {
        this.something == //something calculation
    return this.something

How you’ll read this code? “If we have that `something` undefined, then we calculate it, and store, we always return `something`” Lots of words isn’t it? And the nature of `something` is still unclear..

In Joose land, you can just say that `something` is a lazy attribute:

has : {
    something : {
        is      : 'rw',
        lazy    : function () {
            return //something calculation

As you can see, the complexity of that pattern was absorbed by Joose and don’t pollute the code and programmer’s mind.


Enough of vacant advocacy. In the next post we’ll demonstrate, what all these words means in practice, and how Joose makes your code simpler and more robust.

Stay tuned!


Oh, and we forgot to answer on one very important meta-physical question – “Does Joose works with NodeJS?” It does:


Written by Nickolay Platonov

January 13th, 2011 at 8:19 am

Posted in Joose

Tagged with ,


without comments

Class(‘Joose.Why’, {

If someone would came at our IRC channel and would’ve asked me “Why Joose?” we could have the following hypothetical conversation:

Visitor: So why should I care about Joose? I already code in JavaScript – beautiful, functional language, very expressive, I write 500 lines of jQuery/ExtJS/NodeJS code in a day and my boss is happy – why should I bother?

Me: Lets slow down a bit, and clarify the things – JavaScript is not a functional language. Its a dynamic, imperative language, which has a first-class function. But, for example Perl also has the first class function, closures, etc, almost for 2 decades already and no one thinks Perl is a functional language. You are coding in the imperative language – should have no illusions about that.

V: So what?

M: So, the imperative programs tend to quickly turn into mess (“spaghetti code”). Its just the nature of imperative languages.

V: Not my code!

M: Of course, your’s not. But probably on your next job, you’ll have to maintain the codebase, written by someone else, you know what I mean..

V: Yea, other guys just can’t do the things right..

M: And to limit the mess in the imperative world, clever guys invented to separate the functions into groups, and limit their’s side-effects with a single object. They called those groups – classes and the whole thing – Object-Oriented-Programming.

V: Bo-o-ring..

M: Hey, you can do the same thing in JS, and its fun, take a look:

Class('Person', {

    methods : {
        eat : function (food) {

            return 'yummy'

Class('Person.Tidy', {
    isa : Person,

    before : {
        eat : function (food) {

    after : {
        eat : function (food) {

    methods : {

        washHands : function (food) {
            console.log('washing hands')

        brushTeeth : function (food) {
            console.log('brushing teeth')

        eat : function (food) {

V: Yet another language, compiling down into JS? No thanks.

M: Nah, its pure JS, just a call to `Class` function, with class name and some JSON, describing the class.

V: Hm..

M: This style is called “Declarative programming”.

V: So I can declare that program should “just work” and it will? :D

M: Almost :) Joose provides declarative constructs for the most common programming patterns, like Roles, attributes delegation, types, Singletons, etc, you can also create your own constructs.

V: My own? Like what?

M: Like if you are writing the Router class, you may make it has not only the attributes and methods, but also “routes”. You decide what the semantic of those “routes” will be and how they will behave. Or for example, you can add additional behavior to attributes (validation, binding, laziness, whatever) or methods (overloading, non-blocking chaining, whatever),

V: I see.. Hey, and does Joose works with NodeJS?

M: Sure:

V: Ok, cool. Any links to start with?

M: aha:


Written by Nickolay Platonov

January 12th, 2011 at 4:01 pm

Posted in Joose

Tagged with ,