Moved to Tumblr

Posted in Uncategorized on December 9th, 2011 by Alan Hietala – Be the first to comment

I’ve moved most of my blogging over to tumblr. I find it supports the short bursts of thought I have and I find it easier to keep on top of updates in that format.

find me over at alanhietala.tumblr.com

jQuery camouflaging javascript complexities

Posted in Uncategorized on March 19th, 2011 by Alan Hietala – Be the first to comment

I’ve been writing javascript for awhile and when I was first introduced to jQuery it was such a great experience. Finally DOM manipulation in javascript didn’t suck. As the framework progressed it added more and more convenience that started to hide a lot of the complexity of javascript.

It can be argued that hiding these complexities is a good thing, javascript gives you more than enough rope to hang yourself and shortening that rope will increase developer productivity, reduce errors and lead to an overall better development experience. Unfortunately it seems there is such a reliance on frameworks these days that many of the basics of javascript never actually are understood by many developers.

One of these basics is closures within a loop. This often comes up in event binding when you iterate over a list of items and attach an event to each item.

// vanilla javascript way
var dataItems = ['a','b']
var i = dataItems.length;
while(i) // using descending while loop for efficiency
{
   var ele = createElement('div');
   ele.onclick  = function(dataItem){
           return function(event)
           {
               // do something with dataItem
               alert(dataItem);
           }
   }(dataItems[i-1]);
    i--;
}

This is a standard way of creating a scope containing the variable you want to have available in the event handler that isn’t tied to the loop iteration variable. If we didn’t wrap the function to bind to the click event in another closure every alert would come up as ‘b’.

jQuery for a long period of time required you to do something similar when using their own event binding model.

// jquery < 1.4.3 way
var dataItems = ['a','b']
var i = dataItems.length;
while(i) // using descending while loop for efficiency
{
   var ele = $(createElement('div'));
   ele.bind(function(dataItem){
           return function(event)
           {
               // do something with dataItem
               alert(dataItem);
           }
       }(dataItems[i-1])
   );
    i--;
}

In the above example you still have to understand closures in order to make your code work. Developers still learn the lesson of why their closure is pointing to the last element in the array and still get that “a ha” moment.

In jQuery 1.4.3 they added the ability to pass data arguments in the bind function alleviating the need to create an additional closure to pass the correct arguments. This is a great feature in a framework it cleans up code significantly.

// jquery >= 1.4.3 way 
var dataItems = ['a','b']
var i = dataItems.length;
while(i) // using descending while loop for efficiency
{
   var ele = $(createElement('div'));
   var dataItem = dataItems[i-1];
   ele.bind({'dataItem':dataItem},function(event){
               // do something with dataItem
               alert(event.data.dataItem);
           } 
   );
    i--;
}

The downside is this method completely hides a fundamental language feature from the user. This has the potential to lead to a group of new developers that really don’t understand javascript, only jQuery. This is a bit worrying since jQuery, while being a good framework, isn’t going to be the best tool for the job everywhere.

The recent ecobee android application is good example. It is written as a html5 application and I quickly realized the performance impact of jQuery on a mobile device is enough to degrade the experience significantly on underpowered devices (the sort of android device that you get for free with a 2 year contract).

Javascript isn’t going anywhere and is becoming more important in the land of cross platform mobile applications. This doesn’t mean that developers shouldn’t understand how the language they are using works under the fancy framework they’ve chosen. Maybe it doesn’t matter in 99% of cases and I’m just being pedantic but understanding closures seems like a fundamental concept in javascript and it is worrying that so many don’t understand why their event assigning loop is “broken”.

Froyo 2.2 UX Review

Posted in android on June 30th, 2010 by Alan Hietala – Be the first to comment

I installed the Android Froyo 2.2 update yesterday on my nexus one and thought I would share some initial thoughts on what I like and more importantly what I don’t. I will only touch on the main UI for now. I know many of the stock apps received updates, but they don’t relate to the core OS which is what I want to review today.

read more »

Infinity Pool The Human Sphere Live

Posted in Projects, Ruby on March 14th, 2010 by Alan Hietala – Be the first to comment

The rollout for Infinity Pool that I discussed earlier went off without a hitch. I had some great support from the community on this one and it let me delegate the most dreaded portion of the job (for me anyways) data entry.

I decided to create a handy admin interface that lets Infinity Pool be updated without the need for a programming / SQL background. This takes a lot of the pressure off of me as there are a group of people that are able to do updates now. This is very similar to the approach I took when I was the head of Horde to the Core. Delegate and train those around you to take on tasks when they ask for more responsibility so you don’t end up burning out.

A big thank you to CserZ and Atis52 for doing a lot of the leg work and doing a lot of testing and suggesting some fantastic features to help save them time.

Directions For Google Maps Updated

Posted in Projects on February 8th, 2010 by Alan Hietala – Be the first to comment

Directions with Google Maps has just been updated to version 0.6. There are minor changes in this version the major one being the update for firefox 3.6.

What does Directions with Google Maps do? It is an extremely simple plugin that takes any text you highlight and passes it to google maps to do a search. The search results open in a new tab.

If you find your self highlighting a business address, copying it, opening a new tab, going to maps.google.com and then pasting the address in as a search then this plugin is for you.

It streamlines this process to one click, a major time saver.

Body Scanners Can’t Find Bomb Parts

Posted in Uncategorized on January 22nd, 2010 by Alan Hietala – 1 Comment

Here is a body scanner in action on tv in germany. They plant various objects on a person and have them scanned. Funnily enough they find a pocket knife and a cellphone, but miss the bomb components. These things are useless wastes of money that do nothing more than invade privacy.

Big Wax, So Awesome

Posted in music on January 19th, 2010 by Alan Hietala – Be the first to comment

Big Wax captures everything that I love about hip hop. The great flows, the smart rhymes, the fantastic vibe. He brings a little bit of pharcyde style to the new school.

Infinity Pool Doing Well

Posted in Javascript, Projects, Ruby on December 30th, 2009 by Alan Hietala – Be the first to comment

Just a quick update on one of my side projects Infinity Pool. I’ve pulled it out of beta and it is now hosting 300 accounts with over 2500 army lists for the table top game Infinity created. When I started the project I figured it would be a good way to keep my Rails skills up to date I didn’t think it would still have many daily users this far after launch.

As happens with many table top games the rules are about to undergo a huge overhaul. This means much of the codebase will need to change. This will be an interesting challenge as I will need to maintain all of the current users data while adding in all of the new features that are coming due to the new armies and rules.

This should be pretty fun and some good experience. All I can say is I’m grateful I built out a full suite of tests for my code as having them will be essential to ensuring that things don’t break while the site is under heavy reconstruction.

New Blog Up

Posted in Uncategorized on December 9th, 2009 by Alan Hietala – Be the first to comment

I’ve created a new blog over at www.mediumhard.com. It covers all the gaming related material that I want to talk about but never really set up a platform to do it from. Should be a lot of fun, some good humour and lots of youtube videos. Check it out!

City News – all about the money

Posted in Uncategorized on July 2nd, 2009 by Alan Hietala – Be the first to comment

So there was a story on citynews today about a poor guy that was beaten into a coma. Fortunately there was a surveillance video showing someone that might have crucial evidence to help catch the guy that curb stomped this guy.

What does City news do? Force you watch 30 seconds of a Dove commercial first. This is just disgusting as a 30 second ad will drive away many people that came to watch the video in order to try and help.

Stay Classy CityNews.