Wednesday, May 14, 2008

JavaScript: The Return [no LineTerminator here] Statement

I was just reading JavaScript: The Good Parts by Douglas Crockford, and came across this statement:

I always use the K&R style, putting the { at the end of a line instead of the front, because it avoids a horrible design blunder in JavaScript's return statement.

A while back, I was introduced to using closure to help get rid of unnecessary global variables in JavaScript by a friend at work, along with the book Pro JavaScript Design Patterns. Instead of something like this:

var myString = 'hi';

function doStuff() {
    alert(myString);
}

You write something like this:

var myNamespace = function() {
    var myString = 'hi';

    return {
        doStuff: function() {
            alert(myString);
        }
    }
}();

But, because I like BSD style, I did this, with line breaks before the opening braces:

var myNamespace = function() 
{
    var myString = 'hi';

    return 
    {
        doStuff: function() 
        {
            alert(myString);
        }
    }
}();

When I tried to call doStuff, I promptly got the JavaScript error "myNamespace is null or not an object."

After much head-scratching and debugging, I learned the hard way that ECMAScript defines the return statement like this:

return [no LineTerminator here] Expressionopt ;

Let me put that a slightly different way:

return [!!!NO LINE_TERMINATOR HERE!!!] Expressionopt ;

And that's the story of how I became a convert to using K&R style when coding JavaScript.

Wednesday, April 23, 2008

Avoid Resharper 4.0 Nightly Build 775

If you're trying the Resharper 4 beta nightly builds, I just thought I'd warn that I had trouble with build 775 from 11 Apr 2008, which is currently the newest build marked "Works here". When I installed it, the Resharper items, such as "Find Usages", were disabled in the context menu. I found the issue discussed in the Jetbrains forums, and they said they fixed it in a later build.

Now, I'm using build 780 from 18 Apr 2008, and it's working well for me so far.

Tuesday, January 22, 2008

Amazon Kindle Email Support Does Not Suck

In all fairness to Amazon, I need to explain what happened after my last post.

The bf contacted customer service by e-mail again, and explained his long wait on the phone.

Amazon apologised, and sent a new battery to try.

That didn't fix things, and we let Amazon know by e-mail.

They sent us a new Kindle, and explained we had 30 days from receiving it to return the malfunctioning one.

We received the new one. It works great. We'll be sending the old one back.

And everyone lived happily ever after.