{"id":4,"date":"2011-01-12T16:01:39","date_gmt":"2011-01-12T16:01:39","guid":{"rendered":"http:\/\/joose.it\/blog\/?p=4"},"modified":"2011-01-12T16:01:39","modified_gmt":"2011-01-12T16:01:39","slug":"joose-why","status":"publish","type":"post","link":"http:\/\/joose.it\/blog\/2011\/01\/12\/joose-why\/","title":{"rendered":"Joose.Why"},"content":{"rendered":"<div>\n<div>\n<div>\n<div>\n<h1>Class(\u2018Joose.Why\u2019, {<\/h1>\n<p style=\"padding-left: 30px;\">If  someone would came at our <a title=\"IRC channel\" href=\"http:\/\/webchat.freenode.net\/?randomnick=1&amp;channels=joose&amp;prompt=1\" target=\"_blank\">IRC channel<\/a> and would\u2019ve asked me  \u201cWhy Joose?\u201d we could have the following hypothetical conversation:<\/p>\n<p style=\"padding-left: 30px;\">Visitor:  So why should I care about  Joose? I already code in JavaScript \u2013  beautiful, functional language,  very expressive, I write 500 lines of  jQuery\/ExtJS\/NodeJS code in a day  and my boss is happy \u2013 why should I  bother?<\/p>\n<p style=\"padding-left: 30px;\">Me: Lets slow down a bit, and clarify the  things \u2013 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 \u2013 should have no illusions about  that.<\/p>\n<p style=\"padding-left: 30px;\">V: So  what?<\/p>\n<p style=\"padding-left: 30px;\">M: So, the imperative programs tend to  quickly turn into mess (\u201cspaghetti code\u201d). Its just the nature of  imperative languages.<\/p>\n<p style=\"padding-left: 30px;\">V: Not my code!<\/p>\n<p style=\"padding-left: 30px;\">M: Of course, your\u2019s not.  But probably  on your next job, you\u2019ll have to maintain the codebase,  written by  someone else, you know what I mean..<\/p>\n<p style=\"padding-left: 30px;\">V: Yea,  other guys just can\u2019t do the things right..<\/p>\n<p style=\"padding-left: 30px;\">M: And to limit the mess in  the  imperative world, clever guys invented to separate the functions  into  groups, and limit their\u2019s side-effects with a single object. They   called those groups \u2013 classes and the whole thing \u2013   Object-Oriented-Programming.<\/p>\n<p style=\"padding-left: 30px;\">V:  Bo-o-ring..<\/p>\n<div style=\"padding-left: 30px;\">\n<p>M: Hey, you can  do the same thing in JS, and its fun, take a look:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">Class('Person', {\r\n\r\n    methods : {\r\n        eat : function (food) {\r\n            console.log('yummy')\r\n\r\n            return 'yummy'\r\n        }\r\n    }\r\n})\r\n\r\nClass('Person.Tidy', {\r\n    isa : Person,\r\n\r\n    before : {\r\n        eat : function (food) {\r\n            this.washHands()\r\n        }\r\n    },\r\n\r\n    after : {\r\n        eat : function (food) {\r\n            this.brushTeeth()\r\n        }\r\n    },\r\n\r\n    methods : {\r\n\r\n        washHands : function (food) {\r\n            console.log('washing hands')\r\n        },\r\n\r\n        brushTeeth : function (food) {\r\n            console.log('brushing teeth')\r\n        },\r\n\r\n        eat : function (food) {\r\n            this.SUPER(food)\r\n        }\r\n    }\r\n})<\/pre>\n<p>V: Yet another language,  compiling down into JS? No thanks.<\/p>\n<p>M: Nah, its pure JS, just a  call to `Class` function, with class name and some JSON, describing the  class.<\/p>\n<p>V: Hm..<\/p>\n<p>M: This  style is called \u201cDeclarative programming\u201d.<\/p>\n<p>V: So I can declare  that program should \u201cjust work\u201d and it will? :D<\/p>\n<p>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.<\/p>\n<p>V: My own? Like what?<\/p>\n<p>M:  Like if you are writing the Router class, you may make it has not  only  the attributes and methods, but also \u201croutes\u201d. You decide what  the  semantic of those \u201croutes\u201d 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),<\/p>\n<p>V: I see.. Hey, and does Joose works with  NodeJS?<\/p>\n<p>M: Sure: <a href=\"http:\/\/samuraijack.github.com\/Task-Joose-NodeJS\/\">http:\/\/samuraijack.github.com\/Task-Joose-NodeJS\/<\/a><\/p>\n<p>V: Ok,  cool. Any links to start with?<\/p>\n<p>M: aha: <a href=\"http:\/\/bit.ly\/joose_manual\"> http:\/\/bit.ly\/joose_manual<\/a><\/p>\n<\/div>\n<h1>})<\/h1>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Class(\u2018Joose.Why\u2019, { If someone would came at our IRC channel and would\u2019ve asked me \u201cWhy Joose?\u201d we could have the following hypothetical conversation: Visitor: So why should I care about Joose? I already code in JavaScript \u2013 beautiful, functional language, very expressive, I write 500 lines of jQuery\/ExtJS\/NodeJS code in a day and my boss [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[4],"tags":[6,15],"_links":{"self":[{"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/posts\/4"}],"collection":[{"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/comments?post=4"}],"version-history":[{"count":14,"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/posts\/4\/revisions"}],"predecessor-version":[{"id":19,"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/posts\/4\/revisions\/19"}],"wp:attachment":[{"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/media?parent=4"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/categories?post=4"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/joose.it\/blog\/wp-json\/wp\/v2\/tags?post=4"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}