Archive for March, 2008

Book Reviewed: JavaScript: The Definitive Guide by David Flanagan

March 26th, 2008

JavaScript: The Definitive Guide by David Flanagan is a great book! When I began reading this book I was convinced that (like many technical books) the first couple chapters would contain the important stuff and the content would slowly digress into page filler, fluff, and the book would become just another monitor stand. But not this book! After finishing the formal chapters I started reading the references – YES, this book is so good I’m reading the references! Flanagan has raised the bar for all JavaScript books – this book is in its 5th edition, and has been reviewed by a couple web Gurus (Douglas Crockford, Peter-Paul Koch).

JavaScript is the assembly language of the internet – most of the current-generation web frameworks make heavy use of JavaScript, CSS, and AJAX. If you really want to understand how ASP.NET or Ruby on Rails really works, how AJAX works, how JavaScript libraries work. If itching to push the web browser envelope, to really innovate, then this book is a required read. In addition if you’re coming from a staticly type background like Java or .NET, then JavaScript (a functional programming language) will open your eyes to a different programming model. Once you grock the fundamentals of JavaScript you’ll never be able to look at classical languages (Java, C++, .NET, …) with a straight face again. I highly recommend this book to any web developer from any web framework camp.

View my review on Amazon.

A Completely Normal Post: Our Dog

March 20th, 2008

My blog posts tend to be obscured in programming languages, and techie gibberish, I thought I'd do a normal post on our dog – after all, pets are what blogs are really about, right? :)

Steph (my wife) and I had been toying with the idea of getting a dog, we've been looking at different breeds, visiting shelters, and emailing breeders – I have to give Steph all the credit, she did most of the research. Anyhow, we came across a post on our Kijiji for a mature Soft Coated Wheaten Terrier. Now we have a dog.

Being a Geek and all, I wasn't sure if I was a dog (or cat person), but Belle is a great dog. Her constant need for a walks is a great reminder to take a micro break while working from home.

Belle, our dog.

Author: Adam Kahtava Categories: Calgary, Personal Tags:

Inter / Cross Browser Window Communication Using JavaScript

March 11th, 2008

A quick search on the internet for “Inter Browser Window Communication Using JavaScript” reveals many outdated search results recommending questionable techniques. In the past I’ve fallen prey to many of these ill-advised suggestions. So… I thought, I’d start a small series on JavaScript techniques that I’ve found useful.

This post covers Inter / Cross Browser Window Communications using JavaScript.

A common scenario in web applications is: to have Page A open Page B , then have Page A communicate with Page B or vise versa.

One of the techniques floating around the internet suggests that you use Cookies and a JavaScript setTimeout function that listens for the presence of a cookie. So essentially Page A sets a cookie and Page B listens for this cookie and acts on it.

A alternate solution might be to use the JavaScript Browser and window.opener methods. Using these two methods we can achieve inter / cross browser window communication as long as the Same Origin Policy is withheld – a similar approach can be taken for frame and iframe communication.

An example:

// myNewWindow stores the reference to the newly 
//   created window, this provides a handle for defining 
//   and calling methods in the New Window 
var myNewWindow ='about:blank');

// Let us call the alert method in our New Window 
//   from this window (the Original Window) 
myNewWindow.alert('Hello From Original Window');

// Let us call an alert method in our Original Window 
//   from our New Window. So.. Lets use a timer 
 'window.opener.alert(\'Hello From The New Window\')', 100);

Click here to run this code live in your browser window using a Bookmarklet, or copy the above code into your Firebug Command Line Console.

Author: Adam Kahtava Categories: Firebug, JavaScript, Software Tags:

Something About the Cobbler's Children Having No Shoes

March 8th, 2008

As knowledge workers, software developers and the like, we often find ourselves heads down in the trenches (micro focused, working towards deadlines), while throwing self-improvements and work environment improvements to the sidelines.

As the old phrase goes: “The Cobbler's Children Have No Shoes” – the Cobbler was so busy with other peoples shoes, that he couldn't make shoes for his children. Like the Cobbler I often find myself burried in work, and neglecting the things that could improve my situation.

A couple personal examples: this website (the design has remained unchanged for the past couple years), my desk setup (the mountain of books for a monitor stands and a single 17″ monitor) demonstrate this.

I've since purchases an Ergotron LX Dual Desk Mount Arm, and will soon be upgrading to these Samsung SyncMaster 226BW 22″ monitors, which I plan on running in portrait mode.

How can you improve? What does your desktop look like?


Author: Adam Kahtava Categories: Musings, Personal Tags:

The summer of ’99: Junior-Style / Newbie Programming

March 1st, 2008

Steve Yegge discusses junior-style programming in his post: Portrait of a n00b. After reading Steve’ post I decided to dig up some of my own newbie code – this code is from the summer of ’99.

I got my first real C++ book
Bought it at the local book store
read it ’til my eyes turned red
it was the summer of ’99

I found this code amusing… To keep things short, I included one method, but the entire class implementation is similar – my comments describe almost every facet of what I now regard as relatively simple logic and I’ve completely removed all whitespace.

As Steve puts it:

[I was] making up a temporal narrative in an attempt to carve out a mental picture of the computation for myself. These stories I told myself were a critical part of my mental development as a programmer. I was a child trying to make sense of a big, scary new world. – Steve Yegge: Portrait of a n00b

The code:

 //__Creator:_____________Adam Kahtava
 //__Date:________________June 14, 1999

 //-----Implements the init method defined in the command.h header file
 //-----Keywords and Modifiers are initialized into keyword[], and modifier[1-5].
 //-----(Keywords and modifiers are all separated by semi-colons).
 void command::init(char data[]){
   int j=0;
   int len=strlen(data);
     for(int i=0;i<6;i++){
     //this for loop is run 6 times, 1st for the keyword,
            // and 5 times for the modifiers, and increments i.
     int k=0;
     char temp[20]={""}; //sets temp to "" (the default)
     //goes through "data" copying string into "temp",
     // until delimiter ";", '\0' is encountered or until len >= j 
       temp[k]=data[j]; //copies useful data from "data" to "temp"
       i++; //increments i
       k++; //increments k
     if(i==0){ //is initiated on first "for loop".
       strcpy(keyword,temp); //copies temp to keyword/
     else if(i>0){ //else if "for loop" has been run more than once.
       strcpy(modifier[i-1],temp); //copies temp to modifier[1-5].
     j++; //increments j

Notable difference from then and now:

Back in ’99 I thought everything I wrote was awesome, I thought I was a Code Poet, or a Programming Ninja (with Real Ultimate Power). I thought my descriptive comments were awesome, and probably thought that by removing all whitespace I would be increasing the program’s efficiency. I thought I could learn more by just programming than reading about programming – I recall discarding books and often hacking my way to comprehension. I was clearly disillusioned.

Today I agree with Jeff Atwood that everything I write sucks, I have an obsession with white space, and prefer to thoroughly understand a programming language before verbalizing my proficiency in it. Now I occasionally get complaints that I’m not including enough comments, and I’m still improving and learning. :)

Author: Adam Kahtava Categories: Musings, Programming Languages Tags: