Wednesday, February 18, 2009

Declarative vs. Procedural Formats (and farewell, Freehand and PostScript)

About two months ago, I posted a short note about Gaussian distributions and their uses in, for example, simulating airbrush painting. I included a couple of sample images based on an implementation I wrote in the PostScript programming language.

PostScript was interesting in that it was a full programming language that was designed to run on the printer. In other words, back in 1984, the printer ceased to be just an output device (WOM - write-only memory). It became a programmable computer that was part of the workflow.

PostScript was extremely successful, and in many ways revolutionized the printing industry. However, because all programs are susceptible to bugs, and bugs in a printer were difficult to trouble-shoot and correct, some PostScript workflows had problems. This, among other things, led Adobe to try to find a more stable print format. What they arrived at was a subset of PostScript in which everything was pre-defined so that no custom programs would be running in the printer. This format had been developed for use as Adobe Illustrator's particular dialect of PostScript, but Adobe now called it Portable Document Format (PDF), and began pushing that. In fact, they let PostScript languish, and have not added any new features or updated the language since PostScript 3, about 10 years ago.

This is a somewhat long-winded background to the real point, which has to do with the difference between procedural formats and declarative formats. Procedural formats can contain actual procedures, or scripts, to detail what the receiver should do with the data. Declarative formats are static in the sense that there's no programming involved. The receiver is supposed to know all the possible variants of data, and what to do with them. If some unfamiliar item of data is encountered, it's either ignored or treated as an error. Or, in other words, procedural formats can contain behavior. Declarative formats just contain data, and the receiver has to know how to behave in every possible situation.

So PostScript is procedural. There are some built-in operators for drawing basic shapes, images and text. But most PostScript documents are really programs that use procedures to describe the appearance of the page. Even fonts are procedures in PostScript.

Since procedural formats are prone to bugs, developers often react by seeking a declarative format, such as PDF. Everything you can put in a PDF is spelled out in the definition of the PDF format, and programs and devices that receive PDF are supposed to know what to do with all that stuff.

The problem with procedural formats, though, is the same as the benefit. Everything's spelled out in the definition. You can only do what's in the definition. The airbrush simulation I talked about would not be possible in PDF, because it relies on procedures. Now Adobe or others could define an airbrush feature in PDF, but then a new version of PDF would have to come out, and all the software and devices that can receive PDF would have to be upgraded to add this feature. More importantly, if you wanted to send an airbrush PDF document to someone, you would have to know if they already have upgraded hardware and software to be able to handle it. PostScript doesn't have this problem because the airbrush feature uses the PostScript language, so any PostScript language receiver would process it.

Oddly, later versions of PDF are adding features to support scripting and Flash, which are procedural. In other words, having gone to the trouble of cutting the procedural aspects of PostScript out to make PDF, PDF is now being made procedural again.

In the same way, the HTML standard that was developed for Web pages has been augmented with Java, JavaScript and other procedural content intended to add that programmability back into a format that was deliberately kept declarative. So maybe we should just admit that data formats, for the Web and for printing at least, have to include some procedural elements. Purely declarative formats are just too inflexible.

While I'm waxing nostalgic for PostScript, I'll also tip my hat again to the late, lamented Altsys Aldus Altsys Macromedia Freehand program. Among its many great features, this competitor of Adobe Illustrator allowed users to specify PostScript for each shape that was drawn, so you could create your own effects (e.g., airbrush) in PostScript, and then use them for any shape created in Freehand.

Oh, well.

No comments: