Thursday, October 29, 2015

Call by Name

This evening's lecture covered (among other more mundane things) the paradigm of Call by Name. Sebesta uses general purpose examples. Unfortunately, it's difficult to create good general purpose examples. It's very easy to create examples that make you think the whole concept falls under the heading of REALY BAD IDEA, which is why most general purpose languages don't support it. (And, please don't go the route of arguing that macro expansion is call by name - that's done at compile time which is pretty much the opposite of late binding).

I do most of my coding in PL/SQL these days. Granted, it's a oddball language and it doesn't fully implement call by name, but it sure does do a good job of demonstrating why someone would want it. Try writing a routine that tells Oracle to update statistics on a given table. Did you use the string functions to inject the table name into the SQL call to DBMS_STATS? Well, call by name would have done that for you. Want to create a temporary table, build some indices, add constraints on the fly, etc.? Sure, you can use sprintf in C++, or you can just write general purpose routines in PL/SQL and pass the identifiers in by name.

There are lots of proprietary languages that do this and they all do it for the same reason: databases are intentionally general and referencing items requires either 1) writing a whole bunch of special purpose routines that look basically the same, 2) cutting and pasting commands together, or 3) call by name. It's a great use of a niche feature. Why use tortured examples from general purpose code?

No comments:

Post a Comment