qc.js: QuickCheck for JavaScript

Posted December 5, 2009 by Darrin Thompson
Categories: Uncategorized

I’m really excited to release this to the world.

QuickCheck is a fairly new testing concept that came out of the Haskell community. The goal of QuickCheck is to save time when writing unit tests.

I wanted to try QuickCheck in JavaScript, and I was really surprised to find no one had done a port. So I gave it a whirl and I found it was less complicated than I thought.

Therefore, here is qc.js: QuickCheck for Javascript.

Firebug Console showing qc.js output.

Firebug Console showing qc.js output.

Here’s a quick synopsis of why you might want it:

When we write conventional unit tests we construct a series of test cases to try to exercise the majority of some bit of code.

QuickCheck changes the structure of this. Instead of individual test cases, we take our code and consider some aspect of it’s inputs. We then write functions which check properties of the output of arbitrary inputs to our code.

A property of an add function might be that given two arbitrary positive integers, the result should be larger than each of them.

A property of a sort function might be that given an arbitrary list of arbitrary integers and two different arbitrary indexes smaller than the length of the list, the element at the smaller list index should be smaller than the element at the larger list index. (woo mouthful)

So given a function like that, we can generate hundreds or thousands of arbitrary inputs and run our code and then the property function each time.

It’s fun to work with.

For some code, especially simple pure computation, it’s very quick and easy to write properties and you get good test coverage with less effort than the xUnit framework for your language.

John Hughes, one of the researchers who popularized this concept, has a video showing how to describe arbitrary inputs for normal impure code.

He shows how random unit testing can be creepy good at finding obscure corner case bugs and helping us understand the implications of the code we are writing.

I’ve got in the back of my mind to try using qc.js to throw arbitrary input events at a DOM/JS user interface to weed out weird bugs. At this point I have little more than a vague sense that it should be possible.

But anyway, enjoy.

My BitBucket repository.

John Hughes explains QuickCheck and demonstrates his Erlang implementation.

Advertisements

TJ Ford Called My House

Posted September 4, 2009 by Darrin Thompson
Categories: Uncategorized

I wrote about TJ Ford’s call to my house for Indy Cornrows. How fun was that?

Better Sports Motivational Analogies

Posted August 18, 2009 by Darrin Thompson
Categories: Uncategorized

I have acquired a distaste for motivation and the culture around it. That goes extra for managers who think a speech containing Tiger Woods accomplishments is going to get sales up.

With that said, I was impressed with a bit from a Basketball coach on keeping players accountable for off season workouts. As in, actually doing them. At all. Keep in mind, that this is different from some boss who read ESPN this morning and had a moment. This is an actual coach.

The first thing that’s interesting is that even pros at the highest levels of competition have problems getting motivated during the off season. Some of them don’t do what they are supposed to do, for what appears to be the same reasons as developers and writers.

Second, an experienced coach is telling us that striving for greatness isn’t the key. It’s showing up at all that gets the job done. And his prescriptions are mostly low tech and focused on accountability.

Third, he advocates working in pairs. I wonder if the same managers who think pair programming reduces throughput would think the same of pair workouts.

When there’s a really tough development task to do, nothing gets it done faster than a team of two engineers.

Internet Weird Stuff

Posted August 17, 2009 by Darrin Thompson
Categories: Uncategorized

There just aren’t enough products out there that work like this: First I’m going to unplug it from the USB port on my computer. Now I’m going to smoke it.

This electronic cigarette is the weirdest thing I have ever seen. From what I can tell it’s a nicotine delivery system that doesn’t involve the usual carcinogens.

I’m even willing to concede that this might be a good idea. Might.

Deming on Software: Overtime

Posted June 20, 2009 by Darrin Thompson
Categories: Uncategorized

Deming wrote:

We shall learn from the theory in Chapter 11 that to hold a worker on the job without pay till he has cleaned up the defectives that were detected by inspection of his product, if he is in statistical control, is to charge him with faults of the system.

Deming on Software: Computers

Posted June 19, 2009 by Darrin Thompson
Categories: Uncategorized

Deming wrote:

A computer can be a blessing. It can also be a curse. Some people make good use of computers. Few people are aware, however, of the negative import of computers. Time and time again, in my experience, when I ask for data on inspection, to learn whether they indicate that the process is in control, or out of control, and at what time of day it went out, and why, or ask about differences between inspectors and between production workers, or between production workers and inspectors, in an attempt to find sources of trouble and to improve efficiency, the answer, “The data are in the computer.” And there they sit.

What management needs is understanding of variation. Figures of yesterday plotted on a chart, and interpreted with some understanding of variation, will indicate existence of a special cause of variation that should be investigated at once, if one exists, or that the variation should be attributable to the system.

Deming on Software: Need more Rock Stars

Posted June 18, 2009 by Darrin Thompson
Categories: Uncategorized

Deming wrote:

“Our troubles lie entirely in the work force.” The supposition is prevalent the world over that there would be no problems in production or in service if only our production workers would do their jobs in the way that they were taught. Pleasant dreams. The workers are handicapped by the system, and the system belongs to management.

It was Dr. Joseph M. Juran who pointed out long ago that most of the possibilities for improvement lie in action on the system, and that contributions of production workers are severely limited.