Cleanup When: Before or After?
N/A
We usually clean up after ourselves, but sometimes, we are expected to clean before (ie. after others) instead. Why?
Because in those cases, pre-cleanup is the same amount of work, but game-theoretically better whenever a failure of post-cleanup would cause the next person problems.
Usual: cleanup after. The usual social norm around ‘cleanup’ is that clean up is done after the mess-causing activity, and one cleans up one’s own mess. The post-cleanup rule is widespread, and feels ‘fair’ because it has the useful property that you pay for the mess you make. It is also reasonably self-enforcing in that you are probably ‘fouling your own nest’ if you break it and wait for someone else to clean it up. (Why would they?)
But sometimes before! In some areas, though, this is reversed and the rule is pre-cleanup:
in doing laundry, many households rule that you clean out the dryer’s lint trap before you run your own load (ie. cleaning out the previous user’s laundry lint)
bathroom toilets often have a similar rule: if there’s no toilet paper after use, the next person handles the replacement. (Whether one should put the toilet seat up or down is unclear.)
in math lectures, one may be expected to clean the blackboard from a previous lecture, and leaves one’s own work for the next lecturer to clean
in low-level programming, the operating system can clean (zero out) memory before a program begins, or after a program exits.
Similarly, in loops, one can do various initializations or cleanups before or after a loop iteration. More broadly, any resource handle like network or file or database.
Similar game-theoretically. Pre-cleanup results in the same amount of work on net (1 mess, 1 clean), and is a dominant or self-enforcing strategy in the sense that if you try to deviate from it you will just make more work for yourself & everyone else’s life easier (because now you do 2 cleanups each time). Like post-cleanup, pre-cleanup in these scenarios is also not vulnerable to free-riding exploitation: a lint trap can be only so hard to clean off, a blackboard can be only so hard to clean off, and one only needs some memory zeroed-out (the memory one is going to use) and not 100% of it.
Limiting risks. If pre-cleanup is an equal amount of work and coordination and equally robust to exploitation as post-cleanup, but feels ‘less fair’, then why bother with the reversal? Because pre-cleanup also manages incentives—when it comes to potentially-safety-critical cleanup of shared resources which have limits to how bad the mess can be. You could do post-cleanup, and simply assume that the user before you cleaned it when they were done. But did they?
Worst-case avoidance. An unclean lint trap is hazardous because it might catch fire. Someone rushing into a toilet, who really needs to go, probably does not want to relieve themselves and only then notice that the toilet paper is out (thanks to someone neglecting their post-cleanup duties); with pre-cleanup, they may mince as they scramble to find the replacement roll, but at least they avoid the shame of searching after a most maculate #2. Math lecturers can more easily plan their day if they assume they will need to arrive a few minutes before class to clean up, and head to their next destination as soon as they are done teaching, instead of relying on the previous lecturer (whoever that was) to not be a slob. And in coding, we know all too well that most programs (not ours, of course) are programmed by reckless sociopaths with depraved indifference to correctness or other programs, and that our own programs will crash or stop for a myriad of reasons, and may never reach a ‘cleanup phase’ and do a clean exit (to the point where some argue you shouldn’t even bother with trying to have any kind of controlled shutdown and just write “crash-only programs”); if the program has to zero-out its own memory, many programmers will never do so, and it may be difficult to do so correctly, with potentially catastrophic problems for computer security like cryptography; much better for the OS to consistently erase memory when a program requests new memory.
Pre-cleanup robust to others’ errors. So, in these cases, pre-cleanup avoid errors and negligence of others, and that is why it is a better norm than the otherwise-equivalent post-cleanup.