What's special about YAJAF

Everyone seemingly likes to bash javascript, but on a fundamental level, it's actually a fairly powerful language. When I say "powerful" I mean in the sense that Paul Graham uses in his essay "Beating The Averages", where powerful denotes a language that has more "abstractness" and ability to do what you need it to do. I'm not a lisp programmer although I have the goal to one day learn. This means that, according to Paul, I still look 'up' at lisp not exactly understanding what's going on with all those parenthesis. Over my time hacking with javascript, though, I've developed this strange feeling that javascript is actually 'higher' on the power continuum than C++ and Java.

Now I'm sure I'm inviting angry comments by saying that, but what I mean is that by giving you more access to the structure of the programming language itself, javascript lets you do some interesting things. You can actually write programs in a 'functional programming' paradigm, creating functions that take functions as arguments and return functions as results. You can also write object oriented code, or just procedural code if you wish. The fact that javascript is so flexible is something that I think is commonly overlooked in the language.

Almost all the libraries I've seen have taken the common procedural programming meme that was pervasive in javascript from the early browser days and added some more 'magic functions', sometimes to create objects and sometimes to create complicated widgets or effects. This does work, but for me, is a strange approach to designing UI elements and feels unnatural.

What was my objective with writing YAJAF? Well quoting Paul Graham:

Ordinarily technology changes fast. But programming languages are different: programming languages are not just technology, but what programmers think in. They're half technology and half religion.

Everyone (me included) who develops code can be described by this statement. When I started writing YAJAF, I had a few goals:

All of these goals pointed to one thing: using javascript, something I was loathe to do. I thought well if I have to use javascript I'm going to see if I can create some way to make it feel more natural to me coming from Java, C# and other 'strict' OO programming languages. I thought I was going to have to create some really ugly hacks to make javascript work in an object oriented way. The more I investigated, though, the more I realized the language lends itself to being 'twisted' to do what you want it to.

As I began this project, I kept coming back to the idea in that quote. I started creating a way to write javascript that looks and feels like Java or C# (what I was used to). A thought kept popping up in the back of my mind, surely someone else would be interested in this, no? There are a lot of people with Java and C++/C# religion out there.

I have a design philosophy that great design taps into the tacit knowledge of those you are designing for (why newfangled keyboards, with strange key layouts, will never catch on). Programmers are used to writing code a certain way, with a certain religion. How much UI design experience is out there for Java, C++, and C#? Wouldn't it be great if that could be tapped for this next stage of software development, web applications?

This leads me to one of the big questions people have asked me, is YAJAF a framework or a library? Well in all honesty, the framework piece is very small. The framework involves a few tricks, manipulating javascript itself, and a couple of very small 'autogen' pieces of code to make javascript feel friendlier coming from other OO languages (specifically Java, the last language I did any significant programming in). The windowing toolkit, data io manager, event manager, error handler and other constructs are all part of the library. Unlike other 'frameworks' the goal is not to create ready-bake code skeletons that are then populated, but to create a solid foundation for writing javascript.

All this boils down to the following piece of YAJAF code that could be executed anywhere Yajaf is loaded.

var myPanel = new FX.FXWT.FXpanel();
var myFrame = new FX.FXWT.FXframe();
myFrame.setHW(100,200);
myFrame.setXY(50,50);
myFrame.add(myPanel);

var myButton = new FX.FXWT.FXbutton("press me!")

myPanel.add(myButton);

desktop.add(myFrame);

Voila, we've crated a frame widget with a panel, and a button on the panel.

All of that though is the YAJAF library in action, again mimicking Java. The two things that are special, first I can write code that uses a library in a way thats familiar, and second, the actual library components are written in such a way that I can extend the behavior of them in any way I wish. I could create new 'classes' extending the base 'classes' and adding custom code.

I've come to the decision that I'm going to start opening up the YAJAF framework, but I need to polish off a couple of the rough edges of the framework before I do. Hopefully this quick essay will help those visiting understand what I think makes this framework different.