Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Friday, November 14, 2014

The goTo object pattern in Node.js code

I've been messing around with Node.js lately. Like everyone using Node.js, I've been wrestling with the fact that it forces programmers to use hand-rolled continuation passing style for all I/O. Of course, I could use something like async.waterfall() to eliminate boilerplate and deeply indented nested callbacks. However, since I am crazy, I am using Closure Compiler to statically typecheck my server code, and I don't like the way async.waterfall() defeats the typechecker.

You can stop reading here if you're perfectly happy with using async for everything, or perhaps if you're one of those people convinced that static typing is a boondoggle.

Anyway, I've been using a "goTo object" for my callbacks instead. The essence of the pattern is as follows:

  • Define a local variable named goTo whose members are your callbacks.
  • Asynchronous calls use goTo.functionName as the callback expression (usually the final argument to the asynchronous function).
  • At the end of the function, outside the goTo object, start the callback chain by calling goTo.start().

Here is an example, loosely patterned after some database code I recently wrote against the pg npm module. In raw nested-callback style, you would write the following:

var upsert = function(client, ..., cb) {
  client.connect(function(err, conn) {
    if (err) {
      cb(err);
      return;
    }
    
    conn.insert(..., function(err, result) {
      if (err) {
        if (isKeyConflict(err)) {
          conn.update(..., function(err, result) {
            conn.done();
            if (err) {
              cb(err);
              return;
            }
            cb(null, 'updated');
          });
        }
          
        conn.done();
        cb(err);
        return;
      }

      conn.done();
      cb(null, 'inserted');
    });
  });
};

With a goTo object, you write this:

var upsert = function(client, ..., cb) {
  var conn = null;

  var goTo = {
    start: function() {
      client.connect(..., goTo.onConnect);
    },

    onConnect: function(err, conn_) {
      if (err) {
        goTo.finish(err);
        return;
      }
      conn = conn_;  // Stash for later callbacks.
      conn.insert(..., goTo.onInsert);
    },

    onInsert: function(err, result) {
      if (err) {
        if (isKeyConflict(err)) {
          conn.update(..., goTo.onUpdate);
          return;
        }
        goTo.finish(err);
        return;
      }
      goTo.finish(null, 'inserted');
    },

    onUpdate: function(err, result) {
      if (err) {
        goTo.finish(err);
        return;
      }
      goTo.finish(null, 'updated');
    },

    finish: function(err, result) {
      if (conn) {
        conn.done();
      }
      cb(err, result);
    }
  };
  goTo.start();
};

This pattern is easy to annotate with accurate static types:

var upsert = function(...) {
  /** @type {?db.Connection} */
  var conn = null;

  var goTo = {
    ...

    /**
     * @param {db.Error} err
     * @param {db.Connection} conn_
     */
    onConnect: function(err, conn_) { ... },

    /**
     * @param {db.Error} err
     * @param {db.ResultSet} result 
     */
    onInsert: function(err, result) { ... },

    /**
     * @param {db.Error} err
     * @param {db.ResultSet} result
     */
    onUpdate: function(err, result) { ... },

    /**
     * @param {?db.Error} err
     * @param {string=} result
     */
    finish: function(err, result) { ... }
  };
  goTo.start();
};

Some notes on this pattern:

  • It is slightly more verbose than the naive nested-callback version. However, the indentation level does not grow linearly in the length of the call chain, so it scales better with the complexity of the operation. If you add a couple more levels to the nested-callback version, you have "Tea-Party Code", whereas the goTo object version stays the same nesting depth.
  • As in the nested-callback style, error handlers must be written by hand in each callback, which is still verbose and repetitive: the phrase if (err) { goTo.finish(err); return; } occurs repeatedly. On the other hand, you retain the ability to handle errors differently in one callback, as we do here with key conflicts on insertion.
  • Callbacks in the goTo object can have different types, and they will still be precisely typechecked.
  • The pattern generalizes easily to branches and loops (not surprising: it's just an encoding of old-school goto).
  • Data that is initialized during one callback and then used in later callbacks must be declared at top-level as a nullable variable. The top-level variable list can therefore get cluttered. More annoyingly, if your code base heavily uses non-nullable type annotations (Closure's !T), you will have to insert casts or checks when you use the variable, even if you can reason from the control flow that it will be non-null by the time you use it.
  • Sometimes I omit goTo.start(), and just write its contents at top-level, using the goTo object for callbacks only. This makes the code slightly more compact, but has the downside that the code no longer reads top-down.
  • There is no hidden control flow. The whole thing is just a coding idiom, not a library, and you don't have to reason about any complex combinator application going on behind the scenes. Therefore, for example, exceptions propagate exactly as you'd expect just from reading the code.
  • The camelCase identifier goTo is used because goto is a reserved word in JavaScript (reserved for future use; it currently has no semantics).

For comparison, here is the example rewritten with async.waterfall():

var async = require('async');

var upsert = function(client, ..., finalCb) {
  var conn = null;
  async.waterfall([
    function(cb) {
      client.connect(..., cb);
    },

    function(conn_, cb) {
      conn = conn_;
      client.insert(..., cb);
    }

  ], function(err, result) {
    if (isKeyConflict(err)) {
      client.update(..., function(err, result) {
        conn.done();
        if (err) {
          finalCb(err);
          return;
        }
        finalCb(null, 'updated');
      });
      return;
    }

    conn.done();
    if (err) {
      finalCb(err);
      return;
    }
    finalCb(null, 'inserted');
  });
};

In some ways, this is better and terser than the goTo object. Most importantly, error handling and operation completion are isolated in one location. Also, blocks in the waterfall are anonymous, so you're not cluttering up your code with extra identifiers.

On the other hand, this has some downsides, which are mostly the flip sides of some properties of goTo objects:

  • Closure, like most generic type systems, only supports arrays of homogeneous element type (AFAIK Typescript shares this limitation update: fixed in 1.3; see comments). Therefore, the callbacks in async.waterfall()'s first argument must be typed with their least upper bound, function(...[*]), thus losing any useful static typing for the callbacks and their arguments.
  • Any custom error handling for a particular callback must be performed in the shared "done" callback. Note that for the above example to work, the error object must carry enough information so that isKeyConflict() (whose implementation is not shown) can return true for insertion conflicts only. Otherwise, we have introduced a defect.
  • Only a linear chain of calls is supported. Branches and loops must be hand-rolled, or you have to use additional nested combinators. This doesn't matter for this example, but branches and loops aren't uncommon in interesting application code.

Now, goTo objects are not strictly superior to the alternatives in all situations. The pattern still has some overhead and boilerplate. For one or two levels of callbacks, you should probably just write in the naive nested callback style. If you have a linear callback chain of homogeneous type, or if you just don't care about statically typing the code, async.waterfall() has some advantages.

Plus, popping up a level, if you are writing lots of complex logic in your server, I'm not sure Node.js is even the right technology base. Languages where you don't have to write in continuation-passing style in the first place may be more pleasurable, terse, and straightforward. I mean, look: I've been reduced to programming with goto, the original harmful technology. By writing up this post, I'm trying to make the best of a bad situation, not leaping out of my bathtub crying eureka.

Anyway, caveats aside, I just thought I'd share this pattern in case anyone finds it useful. Yesterday I was chatting about Node.js with a friend and when I mentioned how I was handling callback hell, he seemed mildly surprised. I thought everybody was using some variant of this already, at least wherever they weren't using async. Apparently not.


p.s. The above pattern is, of course, not confined to Node.js. It could be used in any codebase written in CPS, in a language that has letrec or an equivalent construct. It's hard to think of another context where people intentionally write CPS by hand though.

Wednesday, August 03, 2011

g++ unordered_multimap: an exercise

I discovered this randomly several weeks ago while debugging something else at work, and I thought it was worth sharing since the g++ STL is widely used.

Step 1: Save the following file as mapdemo.cpp:

#include <iostream>
#include <unordered_map>

int main() {
    typedef std::unordered_multimap<int, int> int_multimap;
    int_multimap map;
    for (int i = 0; i < 10000; ++i) {
        map.insert(int_multimap::value_type(17, i));
    }
    std::cerr << *static_cast<int*>(0);
    return 0;
}

Step 2: Compile the file:

g++ --std=c++0x -g mapdemo.cpp

Step 3: Load the file in gdb and examine the buckets:

$ gdb -silent ./a.out
Reading symbols from xxx/a.out...done.
(gdb) run
Starting program: xxx/a.out 

Program received signal SIGSEGV, Segmentation fault.
0x0000000000400b4d in main () at mapdemo.cpp:10
10     std::cerr << *static_cast<int*>(0);
(gdb) p map._M_bucket_count
$1 = 15173
(gdb) p map._M_buckets[0]
$2 = (std::__detail::_Hash_node<std::pair<int const, int>, false> *) 0x0
(gdb) p map._M_buckets[15172]
$3 = (std::__detail::_Hash_node<std::pair<int const, int>, false> *) 0x0
(gdb) p map._M_buckets[17]
$4 = (std::__detail::_Hash_node<std::pair<int const, int>, false> *) 0x605080
(gdb) p *map._M_buckets[17]
$5 = {_M_v = {first = 17, second = 0}, _M_next = 0x670c90}

Yes, g++'s implementation of unordered_multimap (known as hash_multimap in pre-C++0x versions of C++) uses bucket hashing, but the size of the backing array is proportional to the count of elements in the multimap, not the count of distinct keys.

Exercise for the reader: Explain what I just did; explain why the result of step 3 is curious; and then explain why the authors might have chosen to do it this way anyway.

It occurs to me that this would have made a decent interview question if I hadn't written it up here. Oh well, I have others.

Sunday, July 26, 2009

What do polyamory and hexadecimal have in common?

The title of this MeFi post reminded me of two related linguistic curiosities: both polyamory and hexadecimal are hybrid mashups of Greek and Latin roots.

"Poly" is Greek for "many"; but Greek for romantic love is "eros". "Amor" is a Latin root. A more fiddly linguist would have coined the term polyerotics (Greek) or multiamory (Latin).

Likewise, "hex" is Greek for "six"; but the Greek root for ten is "deka". "Decimal" is Latin. In this case, more consistent coinages would have been either hexadecadic/deca-hexadic (Greek) or sexadecimal (Latin).

Interestingly, in both cases, at least one of consistent formations (polyerotics*, sexadecimal) is more sexually suggestive to the modern English speaker than the hybrid coinage. Coincidence?


*Actually, "polyerotic" seems to have been adopted by online polyamorist communities as a designation for specifically sexual polyamorous relationships. This is OK, I suppose, although I think the Greeks had it right that romantic love and sexual desire (which they denoted with the same word) cannot be cleanly cleaved in two.

Tuesday, May 12, 2009

Dynamic dispatch is just higher-order programming

Wow, this is pretty terrible coming from a Haskell programmer (via HN):

Dynamic dispatch is a scary programming technique. When you call a virtual method, you never know what might happen. This makes is [sic.] difficult to reason about such code, and code that is hard to reason about is hard to maintain.

This is true in the exact same sense that when you implement a higher-order function, "you never know what might happen". Here is a naive implementation of map in Standard ML:

fun map f [] = []
  | map f (x::xs) = (f x) :: (map f xs)

f could be bound to anything! OMG WTF BBQ!

Likewise here is a Java implementation of printList:

void printList(List aList) {
    for (Object o : aList)
        System.out.println(o.toString());
}

o.toString() could dispatch to anything! OMG WTF BBQ!

Well hold up man, let's try that in ML:

fun printList _ [] = ()
  | printList toString (x :: xs) =
    (print ((toString x) ^ "\n");
     printList toString xs);

Oh that's so much better isn't it. Or not. Basically, you will note that we had to type toString three times instead of once to achieve roughly the same effect.* Note also that this function only works over homogeneous lists; if you want a heterogeneous list, you'll have to define a union type and pack/unpack it yourself.

Object-oriented programming is a form of higher-order programming wherein related data and operations are tightly bound to each other, thus freeing you from the pain of having to wrap them up yourself, thus making it exceptionally convenient to pass data and functions together. Or, in other words, OO programming is just a functional programming idiom with lots of very convenient syntactic and semantic sugar on top**.

Now, the OO community has plenty of bad code and bad guruism bouncing around. Maybe there's somewhat less of that in the functional world. But IMO that's largely explainable by the fact that there are vastly more working OO programmers and vastly more OO code modules than functional equivalents. If the Haskell or ML community were as big as the Java community, there would be just as much terrible higher-order function spaghetti as there is terrible inheritance spaghetti today.***


* Q: Wouldn't the version using Haskell and type classes be as compact as the OO version? A: Maybe, but you'll still have to restrict the function's domain to homogeneous sequences of StringConvertable instance values. Once I hand you a heterogeneous list, you're back in the land of passing toString and packing unions. The only way to do this right is to introduce existential pack/unpack into your language, which basically amounts to introducing a slightly crippled object system with additional syntactic overhead.

** In particular, making super sends and self sends work correctly without OO sugar gets messy. OTOH, conversely, the object-oriented programming languages in common use make certain other kinds of functional programming idioms somewhat baroque — for example, Java's lack of a compact syntax for anonymous functions is a huge pile of Lose — but that's a discussion for another day.

*** In fact, I strongly suspect that with a fair number of kids today thinking that Haskell is the new hotness, that community's in for a rude awakening as they realize that Haskell's going to require style guides and "Haskell annoyances" books and assorted baroque frameworks in order to allow programmers of average ability to assemble software of similar complexity to that commonly assembled in Java today.

Saturday, May 09, 2009

Robert Martin + Ruby = ughhhh

A recent talk by Robert Martin on Smalltalk and Ruby is generating a lot of buzz today. Now, I just gave you the link to the talk, but don't take this to mean that I think you should watch it. I had a whole long writeup-in-progress about all the different kinds of Wrong embodied by this talk and its reception. But there was so much to explain, so many kinds of Wrong, that I just gave up.

Instead, I'll give you an abbreviated summary of a few reactions:

  • Holy shit, Martin is long-winded. A talk of this length with so few ideas* is offensively disrespectful of its audience's time.
  • Estrogen = weak and insipid? Really? Without a hint of irony? And not a raised eyebrow in the room? WTF?
  • The fact that many Ruby hackers seem to think that this was a good talk shows how bad that community's taste is.
  • Twitter's 140 characters are completely inadequate for discussing a subject like this; on the other hand it's a great medium for saying AOL! Which is, I suppose, one reason it has prospered.

I write this post mostly to record how depressed I am that software guruism of such low quality seems to be so popular.

If you want to wash the ugly taste of Martin out of your mouth, I recommend this interview with Leslie Lamport. Ruby hackers have esprit de corps and throw big buzzworthy conferences, whereas Lamport is merely a genius. Guess what the kids end up learning today.


*If you care at all, his entire argument can be summed up in a few sentences as follows:

  • Smalltalk is much more expressive than C++.
  • However, Smalltalk does not "punish you for making a mess"; i.e. you can easily write software that is intricate to the point of being incomprehensible. This is why Smalltalk failed.
  • Test-driven development can provide the discipline which stops the same thing from happening to Ruby.

As I've noted, I think this argument's wrong in so many different ways that it exhausts me mentally even to try to enumerate them all. But just as one angle of attack, note that of the suggested causal factor is false of many failed languages, and true of several popular ones. Forget about correlation not implying causation; I claim that in this case even the correlation is low. Furthermore, long-lasting popularity is so rare for programming languages that it is a fool's game to talk about why unpopular languages never became popular; it's much more fruitful to seek the very rare combination of characteristics common to successful languages.


p.s. UPDATE 8pm: What a relief, lots of other people thought the talk was b.s. too. See J. Robertson of Cincom

UPDATE 2017-10-06: Fixed some linkrot.

Thursday, June 19, 2008

Random notes on four version control systems

From 1996 to 2002, CVS was the only version control system I used. For that matter, it was almost the only system that anybody used, at least in the Unix world. (Well, a few nutty holdouts still used raw RCS...) In odd corners of the Internet, there were rumblings about other systems, but none of them had much mindshare or seemed worth the switching costs.

But somehow, over past five years, the version control universe seems to have opened up dramatically. CVS's competitors got more mature, and projects actually switched to them: Linux went to BitKeeper and git, KDE went to Subversion, etc. I'd occasionally use these systems to checkout and build source code, but I still didn't use them for actual development. Then, in 2006, I got a real job, where we use Perforce with some local wrapper scripts. More recently, I converted some of my personal codebases to Subversion and git, and started using them for real. So over the past two years, I've learned more about version control systems than I did in the previous eight.

Conclusions:

  • There's no reason for anyone, anywhere, to use CVS for new projects. Subversion is stable; it has a strict superset of CVS's abilities; it requires almost no change in your mindset if you're coming from CVS; it runs on every platform that you're likely to have on your workstation or laptop; you can get hosting from a wide variety of providers; and its frontends are roughly as good as CVS frontends. (I use KDE, and kdesvn is only slightly less polished than Cervisia.)
  • CVS to SVN import is pretty good, but not perfect. It will introduce some spurious entries into revision logs, for reasons that I find obscure, and CVS tags won't be seamless.
  • Perforce is a very nice version control system, and has done a lot to change my mind about using proprietary software development infrastructure tools. I particularly like Perforce's ability to prepare a "changelist" from a subset of files modified in your local copy, and perform actions at changelist granularity (e.g., mailing out the CL for review). My major annoyance going from Perforce to Subversion was the fact that svn commit submits all your modified files to the repository, unless you select a list of files manually; and you can't prepare that submission list in advance. (BTW, gvn is probably going to fix a lot of these problems.)
  • The ability to do really lightweight local branches and commits in git is pretty awesome. git will probably be my weapon of choice for solo projects in the future.
  • git seems to have two sweet spots: (a) solo development, where you use it as a sort of glorified Filesystem of Forking Paths, and the unstructured nature of its repositories doesn't matter so much; and (b) hugely distributed development, like the Linux kernel, where speed matters a lot and tending a centralized repository might be intractable to manage anyway. The in-between space where most collaborative projects live --- where you want a medium-sized, canonical, gatekeeper-controlled central repository with a well-defined tip-of-trunk to which everybody syncs and submits --- seems better suited to Subversion or Perforce. (Yes, you can build that workflow style with git, but you have to do the intellectual labor of setting up that workflow, whereas with Subversion or Perforce the wheels come pre-greased.)

Lastly, I've seen some debates about the merits of fully distributed versioning systems like git vs. centralized systems like Subversion or Perforce. I find this analysis fairly insightful. Workflow matters more than your VCS. Think through your desired workflow, and then build a system that supports it; your VCS will be only one part of that workflow system.

At work, we have an automated process for auditing commits, and an awesome code review tool to support that process. After about a year and a half, I'm now addicted to that process. I would find it deeply disturbing to be building "solid" software (as opposed to personal hacks) in an environment where people can commit to the repository without code review. It also seems retrograde to have people perform code review by mailing around patchfiles and having developers eyeball them, or manually apply them to their local trees. And it's obviously not scalable to have a small pool of "committers" through whom all patches must be funneled.

Yet, as far as I can tell, most open source projects run this way: a carefully tended tree with a small number of dedicated committers, who eyeball and then commit patches from the wider community. Craziness.

My ideal repository workflow system would probably be two-tiered:

  • The central repository is where you keep the canonical tree. From the trunk of this tree, you build release binaries, run a centralized continuous build/test farm, etc. The repository is divided hierarchically into modules. All developers can commit directly to this tree; however, each committed patch must be code reviewed and approved in advance by an owner of the corresponding module.
  • Individual developers keep distributed repositories, which work like git. They can manage their own branches, commit at will, etc. When a developer's ready to submit a patch to the central repository, (s)he prepares a changelist in his/her local repository, then submits it as a patch to the central repository. The central repository keeps the patch, but doesn't permit it to be merged into to the trunk until it's reviewed and approved.

Today, you can build an approximation of the above with a Subversion + git workflow. You can buy Subversion hosting from any number of providers, and you can run git on your own workstation without getting anybody else's permission or hosting resources. I suppose the missing piece is the workflow support system, but I doubt the open source community will leave this void unfilled forever.

Monday, May 19, 2008

SML hacking tip: installing on Ubuntu x86_64 by manual transfer from i386

Note: Narrowly targeted Google-food. Skip if you do not program in Standard ML.

Update 2010-05-05: As of Lucid, SML/NJ is now available on 64-bit. So you should probably just upgrade.

Ubuntu x86_64 does not have smlnj (the Standard ML of New Jersey (SML/NJ) distribution); nor does SML/NJ currently build out-of-the-box on Ubuntu x86_64. I elide here a long, dull story about trying to build it --- using 32-bit libraries, etc. --- and cut to the chase: ultimately, I installed it on a 32-bit Ubuntu box, and then manually transferred the files over.

In general, I almost never install software on my Linux box unless it's either (a) completely managed by my packaging system or (b) can be removed by simply rm -Rf /some/directory. Fortunately, SML/NJ more or less satisfies (b).

Assuming you have both a 32-bit Ubuntu install and a 64-bit Ubuntu install available, the transfer process is straightforward. The only trickiness is that there's no simple way to get all SML/NJ packages and libraries at once, so you'll have to apt-get several times if you want a "batteries included" installation.

Steps (unless otherwise noted, perform all these commands on your 32-bit machine):

  • sudo apt-get install smlnj
  • Optionally, do apt-cache search smlnj and install as many of the resulting lib*-smlnj libraries as you want.
  • Optionally, install the following extra packages:
    • ml-lpt ("language processing tools"; includes ml-ulex and ml-antlr)
    • ml-yacc (ML-Yacc)
    These are particularly of interest because probably 90% of ML programmers are also programming language hackers of one stripe or another. (Note that, annoyingly, these packages do not have smlnj as a substring of the package name. And, of course, apt-cache search ml yields a huge fusillade of results because "ml" is a common substring. Couldn't they at least use sml-* or better yet standard-ml-*? Blech.)
  • cd /usr/lib
  • tar -czvf smlnj.tar.gz smlnj
  • Copy the tarball smlnj.tar.gz to your target machine of choice and untar it under /usr/lib
  • pushd /usr/bin && tar -czvf ~/smlnj-scripts.tar.gz `dpkg -L smlnj smlnj-runtime ml-lpt ml-yacc |cut -b 10-` && popd
  • Copy the tarball smlnj-scripts.tar.gz to your target machine, and untar it under a binary directory on your PATH. (I have $HOME/bin in my PATH for user-local executables, so I put it there.)

As far as I can tell, everything works.

Saturday, May 17, 2008

SML hacking tip: fix uncaught exception BadAnchor

Note: Narrowly targeted Google-food. Skip if you do not program in Standard ML.

If you use the Standard ML of New Jersey (smlnj) compilation manager (CM), then you will sometimes get error messages like this:

[bad plugin name: anchor $y-ext.cm not defined]

uncaught exception BadAnchor
  raised at: ../cm/paths/srcpath.sml:436.16-436.25
             ../cm/util/safeio.sml:41.55
             ../cm/util/safeio.sml:41.55
             ../cm/util/safeio.sml:41.55
             ../cm/parse/parse.sml:502.47
/usr/lib/smlnj/bin/sml: Fatal error -- Uncaught exception BadAnchor with 0
 raised at ../cm/paths/srcpath.sml:436.16-436.25

make: *** [default] Error 1

This is CM's way of telling you that it encountered a line in your *.cm that has an extension that it does not understand. In this case, it's a file with a .y extension.

The fix is to correct the file extension (if it was a typo), or perhaps to update to a version of CM that understands the file extension you're using.

In my case, I had been hacking with an ages-old version of SML/NJ, and recently updated to the version in Ubuntu 8.04 (a.k.a. Hardy). Apparently non-ancient versions of SML/NJ expect ML-Yacc files to be named with the extension .grm instead of .y. I renamed my Yacc file, updated sources.cm, and all was well.

Wednesday, May 17, 2006

SML hacking tip: Turn off polyEqual warnings

Note: Narrowly targeted Google-food. Skip if you do not program in Standard ML.

Recent versions of Standard ML of New Jersey (SML/NJ) print a message "Warning: calling polyEqual" when you write code that uses polymorphic equality. Here's how to turn it off:

sml -Ccontrol.poly-eq-warn=false

This works in CM mode, as in:

sml -Ccontrol.poly-eq-warn=false -m sources.cm

I am posting this here as Google-food because I just spent an hour Googling and greping around in SML/NJ sources trying to figure this out.

If you're using SML/NJ interactively, then you can also type

Control.polyEqWarn := false

into the read-eval-print loop. However, this doesn't work when you're trying to invoke the SML Compilation manager in "make" mode (-m), because Control is not present in the default linkage environment. (And the SML/NJ documentation does not specify how to add it; or, at least, I haven't figured it out yet.)

More generally, all control flags (all bool refs in Control) can be toggled at the command line. This is documented in the command-line section of the SML Compilation Manager manual. There, we learn that -C can be used to set control parameters. You can get a listing of all control parameters using -S, as follows:

sml -S

Finally, I just want to remark in passing that unlike, say, "match redundant" or "match nonexhaustive", use of polymorphic equality is purely a performance problem, not a probable logic error. It's therefore highly questionable design to enable a warning message for polymorphic equality by default. The default setting should have been off, but available as a profiling/debugging option.

Friday, December 02, 2005

24 hours to certify Diebold source code?

Via IP today, I learn that the North Carolina State Board of Elections claims to have reviewed and certified the reliability and security of Diebold election machines' source code in less than 24 hours after it was placed in escrow.

All I can say is, North Carolina's State Board of Elections must have software quality assurance engineers the likes of which the world has never seen, engineers who can conjure comprehensive test suites out of thin air faster than mere mortals can even type them up, and who can construct proofs of program correctness in Hoare logic on-the-fly while reading source code, and who don't need symbolic model checkers because they can simulate thousands of Büchi automata in parallel in their heads while filing their fingernails.

Or, hey, here's a thought: maybe the board conducted some kind of sham certification process and rubber-stamped the software without really examining it. Nah...

My previous posts on election machines: Voting Machine Abuse Link-O-Rama; Close your eyes and hum pretty songs and maybe the code will fix itself; Further links on voting machine manufacturers' arrogance; Krugman on voting shenanigans [etc.]; Electronic election idiocy from Tom Zeller.

Monday, October 04, 2004

Slideshow testimonial

Matthew Flatt gave a couple of talks at our dept. last week. One of them was on Slideshow, the very cool cross-platform Scheme-based presentation package which most PLT Schemers have been using for conference talks for the past couple of years. Today, emboldened by Matt's tutorial, I used it to give a presentation to my research group, and I'm happy to report that it went off relatively well.

I'm not sure if Slideshow will wean me off PowerPoint for conference talks, but for quick intra-dept. presentations I've mostly been using LaTeX's slides package; and Scheme's a much better programming language than LaTeX. After hacking around with LaTeX's pathetic \newcommand macros for so long, it was a huge relief to have real data structures and functions. On the other hand, Slideshow's support for mathematical formulae is much weaker than LaTeX's, although I suppose I could hack up some Scheme code to call out to latex and generate a bitmap (the moral equivalent of George Necula's TeXPoint)...

Anyway, Slideshow's definitely worth a try if you have similar needs. Since Matt may not be visiting you anytime soon, the bundled tutorial on the examples page will get you up and running fairly quickly.

p.s. One thing that's cool if you're giving talks with Scheme code: you can cause the code displayed on your slides to get evaluated at presentation time, eliminating the annoying problem of maintaining internally correct and consistent code examples over many revisions of your presentation --- a problem that invariably bites me unless I proofread each slide about a dozen times (and sometimes even then). This feature is almost cool enough to make me want to hack up an interpreter in Scheme for an S-expression-ized syntax of my own language.

Thursday, January 22, 2004

Linux kernel developers can be real asses sometimes

Behold as Linux kernel developers express bizarro way-out-of-proportion bigoted responses to the perfectly reasonable suggestion that it might be worthwhile expending some effort getting kernel headers to be C++-friendly so that kernel modules can be written in C++.