Literate programming (by )

I wish I'd been there for this conversation:

http://www.gyford.com/phil/notes/talks/e/euro_foo_camp_jo_walsh_literate_programming.php

However, I'm far too boring to be able to make it to exciting geek events like that 🙁 Maybe one day, when I've been freelancing for more so have spare money for travel and can take more time away from work...

I've studied literate programming, so I'd probably have been able to help explain it there. My own interesting idea, however, is that a programming language could have inbuilt support for being in development.

Here's what I mean. How many times have you seen:

/**
 * Returns true iff the specified user should be able to perform the action
 * by checking the access control database.
 */
boolean checkAccess (String username, Action desiredAction) {
  return true; // FIXME: implement access control database
}

Or FIXME comments saying that a bit of code ought to be rewritten to be faster, or refactored on general principles, or something.

What I envisage is that you could instead write:

/**
 * Returns true iff the specified user should be able to perform the action
 * by checking the access control database.
 */
boolean checkAccess (String username, Action desiredAction) {
  return test_harness (true, "Access control check for " + username + " doing " + desiredAction);
}

test_harness is pretty much just a function that returns its first argument, or (depending on a compile flag or something) maybe gives the developer (at run time) the option of specifying what it should return, so he can test the behaviour of code when an access control rule is refused (the second parameter being a prompt).

But when you compile the application in "release" mode, the presence of test_harness becomes a fatal error. Thus protecting you from forgetting, and releasing test harness code into the wild.

Another construct would do nothing to the semantics of the program, just prevent it from compiling (with a custom error) when not in debugging mode. This could be done with something like this in C:

#ifdef RELEASE
#error Whoa! Replace this quick hack of a cache with something that actually frees unused memory, will you?
#endif

...but it would be nicer to just write:

#fixme Whoa! Replace this quick hack of a cache with something that actually frees unused memory, will you?

Anyway. Not quite literate programming per se, but something related to it; by giving semantics to certain kinds of comments that have special meaning, we're still blurring the divide between code and comment in a useful way.

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

WordPress Themes

Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales
Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales