JavaScript, Node.js, and the Flying Wedge Anti-Pattern

October 29, 2011

The "Flying Wedge" is the name of a military formation in which troops would march into battle in a V-shaped formation. That same V-shaped "formation" unfortunately has a tendency to show itself in JavaScript and CoffeScript. And in the vast majority of cases, it is bad practice.

Code that's easy...

Node.js Debugging with the Built-in Debugger

October 28, 2011

The HTTP version of the app worked, but the commandline version did not. What went wrong? It was hard to say. The application simply hung, unresponsive. Try/catch and event handlers didn't find anything wrong, and my typical console.log() approach wasn't cutting it, either. I need to fire up Node...

Node.js: Five Things Every PHP Developer Should Know

October 26, 2011

I recently started working on a few Node.js applications. Coming most recently from PHP (and Drupal in particular), I found the transition to Node.js to be surprisingly easy. Pleasurable, in fact. But I had to learn to think differently about a few things.

Below I list the five things I think every...

Five Reasons for Doing Drupal Development on a VM

October 26, 2011

In years past, I used to do my development on a local machine, and then push my work to a remote server for testing. About two years ago, though, I switched my environment. I began using virtual machines instead of physical servers. Configuring them for Drupal, I could do my Drupal development locally...

Node.js: Connection Pools and MongoDB

October 26, 2011

Node.js can interact well with MongoDB using the MongoDB native driver. The driver comes with plenty of documentation. However, one feature that isn't explained clearly is the pooling system.

The MongoDB Node library can create a pool of connections to the database that can then be shared throughout...

Node.js Automated Testing: A Quick Intro to Writing and Running Tests

October 21, 2011

Node.js does not come with a formal testing suite (though there are several available). However, it comes with the necessary tools for writing simple and effective automated tests. This is a quick explanation of how to write simple tests for Node.js code. We cover the directory structure for testing...

In-depth resource on how browsers work

August 22, 2011

How Browsers Work is an in-depth resource -- about 50 printed pages long -- explaining how a browser begins with HTML, CSS, and JavaScript files, and ends up with a display.

The clear explanation, based on FireFox and Chrome/webkit, explains many of the nuances that frequently cause edge-case bugs...

Good Code: A Useful Definition

August 19, 2011

What is "good" code? We toss around all kinds of high-level definitions, but these are usually either hopelessly vague or hopelessly complex. This month's Pragmatic Programmer magazine offers a fantastic definition, summarized on this card:

(Apparently originally from Agile in a Flash)

Tim Ottinger...

Microbenchmarking PHP: Switch Statements are Slow

August 18, 2011

There are very good uses for Switch statements. They can be great for nesting logic. But sometimes they are used as a way to (essentially) map a name to a value. In such a scenario, the body of the case is just a simple assignment.

After noticing this pattern a lot recently, I thought I'd benchmark...

Your Code is Not Your Baby

August 17, 2011

In the introduction to The Gay Science, Friedrich Nietzsche famously compared writing to giving birth:

"[W]e have to give birth to our thoughts out of our pain and, like mothers, endow them with all we have of blood, heart, fire, pleasure, passion, agony, conscience, fate, and catastrophe."

Ever...