In my enthusiasm to get the blog off the ground, I started off with a rather deep article. It's probably a reasonably obvious concept, but I wanted to rewind back to the beginning. I wanted to write about ZJS, why I created it and what I hope to accomplish.
My programming language background is C, C++, Java and (lately) C#. This family of languages shares many things with JavaScript, but JavaScript is clearly a different creature. On the surface, JavaScript looks more like C because functions are one of its primary means of organization. In fact, my early exposure to JavaScript never gave me any idea that it was more than a type-less derivative of C with some homage to OO concepts – we could have objects with properties.
When I was put into my first large project involving JavaScript, I did what I usually do: I tried to find better ways of organizing my code and started to learn all that I could about the language itself. It was then that I discovered closures, object literals and a whole universe of libraries attempting to fill in the missing pieces. These missing pieces come, I suppose, from the lack of declarative ability in JavaScript.
Everything in JavaScript is imperative. You don't declare functions, you create them! You can create a function more than once, and the second will simply overwrite the first! Amazing. Well, to me anyway. You see, one of the things that I found that profoundly impacted my entire way of thinking as I moved from C to C++ was the ability to declare things. Not just functions, but a mystical new thing called a “class”.
As I see it, the concept of a “class of objects” is one of the most powerful tools of thought we have in the realm of programming languages. Even when stripped of many of the things that we might define as very important (like interfaces, access protection and even inheritance), the act of grouping code and data in to a cohesive bundle is, by itself, a massive improvement over the alternative.
That alternative is an amorphous and monolithic mass of code. Without the class, a maintainer is lucky if the original authors had followed any convention to aid in understanding: either of function names, order of placement, separation into files or some comments. I've only had the pleasure of working on one project (in C) where the creators had the discipline to establish rigorous naming conventions and followed standards that produced an intuitive and well structured program. That was a good thing, because it was a mere 300,000 or so lines of code. A medium sized program really, but of a size that maintenance would have been intolerably painful otherwise.
Fast forward about 15 years from that experience and I found myself trying to deal with a significantly smaller body of JavaScript code (only about 10,000 lines). It was a mess. Functions seemed to be randomly placed, had few if any comments (wouldn't want to pay for their download after all) and was generally a nightmare to maintain. The sad part is that it had been written by a team of senior level Java programmers who would never have considered doing such violence in that language.
So that's the baggage I carry. I wanted very much to push the boundaries (at least of my understanding) and see just how far one could take the features in JavaScript towards a more declarative style of object oriented programming. At the same time, however, I didn't want to strip the language of its most powerful, dynamic features by creating a framework that didn't mesh with its spirit.
So, what do I hope to see from all this? Of course I would love to see other libraries or widget toolkits build on top of ZJS so that we could stop reinventing the wheel. While that would be ideal, I think that outcome is highly improbable for numerous reasons. Even so, I think there is every chance that those working on other libraries might be inspired by what they find in ZJS and mimic its solutions. Without trying to boast, I think ZJS has achieved a level of succinctness and expressiveness that puts it above just about any other approach of which I am aware. Granted this is highly subjective, but it was that lack of crisp expression of intent without compromising the language that prompted me to start ZJS in the first place.
As I see it, if other libraries imitated (or outright copied) some of the things found in ZJS, I would be delighted. In the meantime, I'll continue to enhance ZJS and treat it like my little think tank. There are many areas I still want to address or redress. I suppose there will always be room for improvement! And I welcome any feedback along those lines: positive or negative.