Thursday, November 25, 2010

New exciting work to be done

Hi ppl,

long time no see. Fortunately my new business (creating www software) is growing fast, so I didn't have much time to write but a lot of stuff happened.
I got a new job, a new car and and moved to a quieter city :)

The car:



(not the actual photo, but damn close)
Black Jeep ZJ '96 - sounds pretty old - yep but the advantage is that its a V8 engine with over 200HP, makes a lot of fun:)


The city:



Sopot - it's like the Polish Beverly Hills - "the place to see end be seen" in the summer, now in the early winter its just a nice place to live :)

The job:



UseItBetter.com - a great new adventure. A very innovative project - recording everything that happens on a flash website -> store it -> analyze it -> draw conclusions. The basic idea here is to know what you need to change on a flash website to raise user experience. There are some really interesting technical difficulties that will eventually need solving:

1) The project has potential - fast growth isn't a problem if you have the infrastructure or use a cloud (and your application has basic scalability possibilities)

2) A lot of simple traffic coming in - recording user traffic is a lot of inbound traffic. The architecture has to take into account that traffic can vary with pretty big amplitudes.

3) Big OLAP queries to execute - trends over time, user behavior changes. Analytical queries have a very much different profile that the usual website OLTP stuff, some things just take long, some can be made faster (I hope ;) ).

4) What happens if you get a client that wants to record a lot more? Is the system scalable enough to handle bigger players or is the query execution time multiplier equal to the size of the database?

Some interesting month are ahead, we are yet to an official product start (it's currently in semi open BETA). I hope I will have the pleasure to write about interesting problems, and their smart resolutions.

I didn't write anything about my business, but that's another topic all together :)

See you soon,
Piter

Sunday, April 4, 2010

Some feedback on Google Closure Templates

We've been using GCT at myvimu.com (My Virtual Museum). After the introduction of the new technology, we had some problems that needed solving:

1) The GCT compiler is a pretty unhandy tool, after some php modifications, we managed to get results faster.

2) No predefined directory/file handling structure was a big problem. I personally hate the directory maze of some developers, we had to keep it simple yet practical. A simple structure of front-end ( guest users ) and back-end ( logged in users ), and an additional categorization per structure, made every decision about where everything should be really straight forward.

3) Loading of the templates should be automatically. We'll soon migrate to a multilingual system, that has to work automatically from the js template side, so auto loading was an issue, but no more.

Google Closure Tools is a great tool, that, if used with a little brain, can make Your js look and feel a lot better. It's something worth recommending.

Saturday, January 23, 2010

Organize your spaghetti javascript/java with Google Closure Templates


If you ever developer something in javascript that has to have some html, its a real chore, for me anyway. Plain dom manipulation is pretty easy, but what do you do when you need to insert some dom nodes that weren't there before? I think it's pretty common to write something like this:

//jQuery javascript:
 javascript: 
 var someHTML = 'A new paragraph!';
 jQuery('#paragraphContainerDiv').html( someHTML ); 

The code, if you have jQuery of course, should insert the paragraph as a new node in the selected container. When you're a more advanced js developer, you'll probably try to generate the nodes with some js functions and then append them to the containers and so on, which by the way make things a lot more complicated to the person that maintains the code later on. If you are smart you'll probably think about templating. The normal approach would be to write some functions in which you input some template data:

//javascript: 
 var Template = {
 helloThere : function (name){
  return 'Hello there '+name+' !';
 }
 } 
 document.write(Template.helloThere('Piter')); 

When you paste the code into you firebug, you probably should see a "Hello there Piter !
" text. What we have achieved is to unbind the html from the javascript, which is the right way to go, but still when you look at the Template.helloThere() function, its a pretty messy piece of code. Let us add some internationalization features like so:

//javascript: 
var Template = {
 helloThere : function (hello, name){
  return ''+hello+' '+name+' !';
 }
 }
 
 //english
 document.write(Template.helloThere('Hi there','Piter'));
 //polish
 document.write(Template.helloThere('Witaj','Piter'));
 //french
 document.write(Template.helloThere('Bonjour','Piter'));
 /japanese
 document.write(Template.helloThere('Konnichiwa','Piter'));

It's not hard to imagine how this template would look like within a real exapmle that has 20-50 html tags, full I18n support and additional data variables. Even if you would pass the variables as arrays the main problem stands: spaghetti html and js.
Fortunately there is a way to rapidly develop templates and manage the very easily, especially in a team when the js programmer and web developer are two different people. The answer is Google Closure Templates. The pretty recently featured Template engine is used among the most commonly used G applications like Gmail, co as Google says it's well battle-tested :-), and well documented. It not only speeds up development of Javascript/Java but also makes the code a lot easier to maintain and localize. Let's Have a look on what the code above would look like in GCT, but first you need to follow the instructions on Google code Closure site, in a shortcut (for windows/javascript):

  1. You need to install Java Runtime Environment,
  2. Download the closure template compiler (for js)
  3. Unpack the library and put it in some locally hosted folder (you need Apache or some other web server)
  4. Create a simple.soy file and start editing it

//soy example
{namespace Template}

/**
* Simple soy file example
* Here you declare variables via the documentation comment
* @param hello - the hello message
* @param name - name of the greated person
*/
{template .helloThere}
 
  {$hello} {$name} !
 
{/template}

What you want do do is to compile the simple.soy:
java -jar SoyToSrcCompiler.jar --outputPathFormat simple.js simple.soy

If you get some exceptions... deal with them :) They are usually pretty strait forward and easy to understand. If there are no errors, you'll get a simple.js that is the javascript compiled version of your template file. After linking soyutils.js and simple.js to a html file you can post the code in a script section or just into firebug:

document.write(Template.helloThere({hello:'Hi there', name: 'Piter'})); 
 document.write(Template.helloThere({hello:'Witaj', name: 'Piter'})); 
 document.write(Template.helloThere({hello:'Bonjour', name: 'Piter'})); 
 document.write(Template.helloThere({hello:'Konnichiwa',name:'Piter'})); 

The code looks very similar to the simple javascript function but it has a real advantage, you can request a ready template from your web developer and just fill the gaps with variables, what makes developing really fast and easy for everyone. You even can put your translations in another file so your translators can work at the same time too.

Summarizing Closure Templates have every advantage a normal e.g. php based template engine has, like variables, globals, loops, conditional functions and more. Everything is documented at http://code.google.com/intl/pl-PL/closure/templates/docs/overview.html so as my Linux addicted friends would say RTFM and start using Google Closure Templates. Also there is no catch, Google serves it free under the Apache License 2.0 and encourages strongly to use them.

BTW Still hate Bloggers text editor... that is why every post looks different :)