Nancy Typing

ziggy on 2006-02-24T17:42:47

We all know about Duck Typing (if it walks like a duck, and talks like a duck, then it's probably a duck). Works fine most of the time with dynamic objects (in Perl, Ruby, Python, etc.). Also used as a defense against big up front static compilation regimes (in C++, Java, etc.) that claim to help you from making type errors by catching them early (but actually give you more stuff to type, since you're always using casts to turn off the type checks every line or three).

Dave Herman has a new take on the situation - Nancy typing. In typical lispnik fashion, Dave is picking on Perl's DWIMery in this example:

In some cases, the heuristics for conversion are arguably relatively clear, but sometimes the language is so eager to find some way to make the operation consistent rather than simply give an error (and force the programmer to be more explicit) that extremely bizarre and unpredictable behavior ensues. [...]

[E]very once in a while, the system reported a false positive[...]. And it just so happened that in each one of these cases, the name in the record was "Nancy." The explanation is that the programmer had accidentally used the numeric equality operation, rather than string equality.

Yep. "Every" name numifies to 0, except for Nancy, who numifies to NAN. Everyone is thus numerically equivalent to everyone else, except for Nancy, who is numerically equivalent to no one (including herself).

Whoops. That's a, um, rather interesting form of silent failure. If you're wearing your Lispy hat today, you can extrapolate this into a proof that duck typing fails thanks to dear old Nancy.

The rest of you can take this opportunity to add dear old Nancy to your smoke tests. :-)

Update: This bug exists in 5.6.0/5.6.1, but is fixed as of 5.8.0. So you can either worry about Nancy, or just upgrade to a reasonable version of Perl. :-)


google nancy perl

mr_bean on 2006-02-25T11:30:11

This is a fast-breaking story, which Google hasn't picked up on yet. The first result it turns up for Nancy Perl is The Sexy Librarian