Currently, maintainer scripts in .deb packages are typically generated by debhelper. Debhelper inserts snippets of shell script to perform specific tasks. If the snippet has a bug, all packages need to be rebuilt.
It strikes me that a more declarative approach might work better:
#!/usr/bin/debian-postinst create-system-user httpd update-config-file /etc/blipblop.conf
Alternatively, the snippes could just be moved to external tools:
#!/bin/sh set -e case "$1" in purge) dpkg-remove-logfiles --package=blipblop esac
Edit: Old discussion page.