Friday, December 23, 2011

Appcelerator, JavaScript, and Lint

I've been using Appcelerator for a few months now. That means programming in JavaScript, and it's a little scary: out of the box, JavaScript is too forgiving. Things like accidental globals don't belong in production software. But it's tough to keep them out of a couple thousand lines of code without some help from tools.

For me, the right tool is JavaScript Lint. It's easy to integrate into an Appcelerator project. Suppose you're working on fooapp, with a top-level directory of the same name:

  • Download and install JavaScript Lint for your OS;
  • Copy jsl.default.conf from the installation directory to fooapp, and rename it to jsl.conf;
  • Edit jsl.conf. Set always_use_option_explicit to +
  • At the bottom of jsl.conf, insert:

https://gist.github.com/1515692

The +define lines tell JavaScript Lint about the globals in your project, so that it doesn't report them as problems.

Now, if you run jsl -conf jsl.conf from the command line in fooapp, it checks your JavaScript and sends the output to stdout. You may also be able to hook the command up to your text editor so that every save automatically runs the checks.

And it's easy to skip safe problem code. I had some third-party code that was triggering lots of warnings, but I trusted the soundness of the code and didn't want to change it. So, to eliminate the warnings, I bracketed the code within a couple of special comments:

https://gist.github.com/1515697

Sunday, December 4, 2011

The Real Family Values Candidate

Why are the socially conservative Republican primary voters, alleged champions of family values, so ready to give Newt Gingrich a pass?

To recap: Gingrich is on his third marriage. He cheated on his first wife with the woman who became his second wife, and he cheated on her with the woman who became his third wife. You don't have to be a liberal Democrat to think that Gingrich is a piece of shit. Gingrich says that he's asked God to forgive him. Is that all it takes for the religious right to hypnotize themselves?

Of course, there is one candidate in the 2012 race who embodies traditional family values. He's a faithful spouse and a devoted parent. He's a role model, a mensch.

I'm talking about the guy in the White House right now. Obama is way hotter than Gingrich, but even Fox News has not been able to dredge up any credible scandals. Maybe the DNC should print up some bumper stickers:

    Obama - He Keeps It Zipped