22 December 2008

My Favorite Mouse

As a programmer, I naturally spend a good portion of my waking hours--if not the majority--in front of a computer. This didn't seem a problem for the first quarter century of my life, but then about three years ago, I started experiencing pain in my mousing wrist. My first thought was that the beginning of carpal tunnel syndrome was setting in, which freaked me out.

I immediately set out to try more ergonomic input devices, and I switched to a pen input device at home and a radical ergonomic mouse at work. While the pen input device worked fairly well, the ergonomic mouse I chose proved to be the single greatest purchase I've ever made. Since starting to use it, I no longer have any pain in my wrist. I now realize that with the many viable ergonomic options for mousing that are available, no computer user should be using the very dangerous standard mouse.

Anyway, the mouse that I wholeheartedly recommend is the 3M Ergonomic Optical Mouse:



It is definitely a strange looking mouse, but the strange shape is what makes it work so well. This mouse fixes two problems with traditional mice:

1. Traditional mice force your arm to twist, causing your tendons to rub against each other, which causes inflammation and pain. By letting your arm sit in a much more natural arm-shaking position, the ergonomic mouse prevents this.

2. When using traditional mice, your wrist, with all it's delicate parts, does all the moving. The ergonomic mouse, on the other hand, keeps the wrist straight and the arm becomes the moving part.

So again, I highly recommend this mouse (or a pen tablet) to all computer users, and especially to programmers.



(Note: Just in case anyone thinks I am advertising for 3M, no, I am not in any way sponsored by or affiliated with them.)

16 December 2008

Industrial Strength Application Development in JavaScript

Inspired by the work of Douglas Crockford, I have been developing a JavaScript application using full blown development techniques. JavaScript is definitely a misunderstood and underestimated programming language, and I have found it to be a pretty good hybrid of object-oriented and functional techniques. I have even done some cool things with it that would not be possible in a statically typed language. I have found that with proper unit testing and debugging tools, its dynamic typing has caused me few problems.

So what tools can I recommend for industrial development in JavaScript? Everything below is an absolute must for my needs:

jQuery
  • What it does: Ajax, DOM-modification, and general utility functions
  • As Jeff Atwood pointed out, there is no good reason to write low-level JavaScript to manipulate the DOM with today, now that there are tons of high quality JavaScript libraries to help out.
QUnit
  • What it does: Simple unit testing, compatible with jQuery
  • I tried out a few other unit testing frameworks, but QUnit is the simplest one by far and just gets the job done.
JavaScript Lint
  • What it does: Identifies most textual errors in JavaScript files.
  • Indispensable tool to find that missing semicolon that is causing that weird error.
  • Note for TextMate users: Use the JavaScript Tools bundle instead of downloading it from the official site.
Firebug
  • What it does: Firefox plugin. In addition to excellent DOM manipulation, it makes a great JavaScript debugger.
In Addition, Mozilla's JavaScript Reference is a must for any serious JavaScript developer.

Well, I hope this gets you started. If you have any other suggestions, let me know!

02 December 2008

Javascript's Undeclared versus Undefined

I learned the hard way that undeclared is different than undefined. If you try to test the simple way for an undeclared variable, you get an error, which in my environment means an annoying pop-up.
/* var a; */  // undeclared
var b; // undefined

// This would cause an 'object undefined' error
/*
if (a) {
alert("a is defined");
}
else {
alert("a is undefined");
}
*/

if (typeof(a) == "undefined") {
// this will be executed
alert("a is undeclared or undefined");
}
else {
alert("a is declared and defined");
}

if (b) {
alert("b is defined");
}
else {
// this will be executed
alert("b is undefined");
}

if (typeof(b) == "undefined") {
// this will be executed
alert("b is undeclared or undefined");
}
else {
alert("b is declared and defined");
}