Changing Times
Times change, and with them the way we do things.
Ever since I started to program, the way you save stuff to disk has followed the same script:
- Make a file object
- Create the file (deleting the old file as necessary)
- Open the file for writing
- Write stuff
- Close the file
I’m writing a cleaned-up File abstraction for Tinderbox 6, and for the first time I realized that nowadays this doesn't make sense.
- Stream what you want to write into memory
- Create the file with that stuff
In the old days, we had to write stuff into an open file because there was no place to save things beside the file. We don’t do that any more; you make some sort of logical stream or buffer in memory and you write stuff there. You do this before you touch the file system because if for some reason you can’t write stuff – because your realize the data is invalid or inconsistent or because something is unbaked – you want to find that out before you go messing with files and disks. Nowadays, there‘s plenty of memory.
I’m not sure that our file API needs open, close
, or write
. Just "create a file with these contents.