Nov 7, 2008

Part 1: Java syntactic sugar for Javascript

In my spare time I have been playing around with javascript a lot. I'm trying to sharpen my javascript skills by writing a web application that looks like a desktop application using pure javascript and keep away from HTML as much as possible. I have done this using ExtJS.ExtJS is a javascript framework and GUI toolkit that encapsulates common widgets and functionality into classes and uses javascript object orientation capabilities extensively. A typical ExtJS class looks like this:
  1. Ext.data.MemoryProxy = function(data){

  2.   Ext.data.MemoryProxy.superclass.constructor.call(this);

  3.   this.data = data;

  4. };

  5.  

  6. Ext.extend(Ext.data.MemoryProxy, Ext.data.DataProxy, {            

  7.   load : function(params, reader, callback, scope, arg){

  8.     params = params || {};

  9.     var result;

  10.     try {

  11.       result = reader.readRecords(this.data);

  12.     } catch(e) {

  13.       this.fireEvent("loadexception", this, arg, null, e);

  14.       callback.call(scope, null, arg, false);

  15.       return;

  16.     }

  17.     callback.call(scope, result, arg, true);

  18.   },        

  19.   update : function(params, records){

  20.        

  21.   }

  22. });


This code snippet is creating a new MemoryProxy constructor, as a member of the Ext.data object, i.e., it's package. Then it uses Ext's Ext.extend to make some magic and create a protype inheritance from Ext.data.DataProxy. The thrid parameter to Ext.extend is an object literal expression that will become part of Ext.data.MemoryProxy's prototype, the functions present in this object will override the functions that were already present in Ext.data.DataProxy.So what's the problem with this code you may ask.... Absolutely nothing. This is pretty much standard OO Javascript. Many frameworks are already using this pattern and it has been working great.Now I do have a problem with code... it's not very intuitive to a Java developer. I know, I know... who cares about them, Java developers should be developing JAVA right? Well that's a valid point. But still, I consider myself a Java developer so I do care about us :D. So my idea is to create a small library that would add some syntactic sugar to javascript to make it a bit more like Java. Still with me? Like the idea?To be continued (on my next post...)

Nov 6, 2008

CSS display woes...

So for a proof of concept I'm programming, I tried modifying an existing javascript tree widget implementation (from ExtJS). The effect I wanted to achieve was this:


+ Root Node
Content for the Root Node
+ Child Node
Content for the Child node
+ Another Child Node
Content for the Other Child node


Now, when doing this, the actual html that is rendered looks something like this:


___________________________
|+| Root Node |
| |Content for the Root Node|
|_|_________________________|___
| |+| Child Node |
| | | Content for the Child node|
|_|_|___________________________|_____
| |+| Another Child Node |
| | | Content for the Other Child node|
|_|_|_________________________________|


The big problem I was having is that the node contents we not expanding to the fit the with of the page, i.e., fill what's left of the with. This was happening because the contents were rendered using a span tag and it because it's a inline element it just expands to the width of its contents. Using a div or changing the display of the span to block would not work either because block elements have a new line infront and after them. Using the "align:left" property would cause the div to align all the way to the left of the page.


The Solution? You may ask... Well, just hack it and use tables. I know it sucks, I hate it, I feel dirty by doing so, but to the extent of my knowledge there is not much else I can do. I wonder if it was so difficult creating an element in HTML that would allow you to display them inline and fill all the with to is to the left of them? Was it really that difficult????

First Post

So, this is the first blog post of many (I hope) and I though I would give some information about myself and my background.

My name is Carlos Zúñiga, I currently live in San Jose, Costa Rica. I work for an e-tailer company from the USA that has a development center in Costa Rica.
At the time of this writing I'm 3 weeks away from getting married to my lovely girlfriend of 3 years, Maricel, as you might expect, we are swamped with stuff to do.

As for the geek in me, I'm a Java developer. I have about 6 years experience developing Java applications mostly for the web.
I'm very interested in Java and other JVM languages, and the whole ecosystem around the platform. I also enjoy programming in Javascript and I consider myself pretty savvy in this area.

I have had the opportunity of working in companies where Agile methodologies have been used and I gotta say that I really like them, specially Scrum and eXtreme Programming. I firmly believe that Pair Programming and TDD have a deep impact in the quality of software.

So I guess this is it for now, but hopefully I will write some more in the near future.