Uncategorized

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”.

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.

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.

Canada Bans British MP

Posted in Uncategorized on March 20th, 2009 by Alan Hietala – 1 Comment

Canada has banned a British MP from entering the country due to his anti-war stance. Sure his opinions may be unsavory to some but the last I heard this wasn’t a ban-hammerable offense.

Get it together Canada, we used to be a nation of peace keepers, now we bar our allies MP’s from entering our own country due to their political convictions? This was a decision passed down by our Minister of Citizenship and Immigration, Jason Kenney. Feel free to let him know what you think.

Destruction of Urban Farm in LA

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

In 2006 the city of LA destroyed a community farm on land that was donated to the community after the Rodney King riots. Now this land has been sold to developers and over 350 gardens were destroyed that helped feed some extremely poor people. These gardens also provided an outlet for youth, something to believe in, and now there is nothing, a barren wasteland.

No one in the community was consulted and no alternatives proposed. Since these people were extremely poor, they just didn’t matter. What a sad reflection of the society we live in today.

Send Direct Message – Twitter4r

Posted in Ruby, Twitter, Uncategorized on February 12th, 2009 by Alan Hietala – Be the first to comment

I’ve been getting a lot of incoming search traffic looking for how to send a direct message using Twitter4r. Firstly RTFM if you can’t do that…

require('rubygems')
gem('twitter4r', '0.3.0')
require('twitter')
require('time')
 
login = "xxxxxx";
password = "xxxxxx";
 
#make the connection
 
twitter = Twitter::Client.new(:login =>; login, :password =>; password);
 
status = Twitter::Message.create(
   :text => 'I can\'t read RDOC',
   :receipient => 'anotherlogin',
   :client => twitter)

Hope that helps.

Backwards or Forwards?

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

clashI was listening to the radio today and was reminded of one of my favourite clash songs. White riot has this fantastic lyric in it that says:

Are you taking over
or are you taking orders?
Are you going backwards
Or are you going forward

Tom Morello from Rage Against the Machine told a story about how he stuck those lyrics on his fridge in college and asked himself those questions every day when he looked at it. I don’t think I ever found my lyrics to stick to the fridge, but Tom, I think I might borrow yours.

Blog Resurection

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

I’ve resurected my blog that had been sitting stagnent for a while. I’ve moved it to my own hosting and switched over to WordPress. I hope to post a lot more frequently. Hope you enjoy.