Naming is hard (so don't)
By traviscj
- 3 minutes read - 501 wordsA lot of times I just want to record something. This should be one of those things computers are good at. Turns out this is a bit harder than it seems: many editors make you name a file to save it.
One easy-sounding way to record something is:
- open up a text editor
- mash the keyboard until the thought is out of your head and into the text editor
- (hard part starts) what do we name that file?
- where do we put that file?
- do we remember to save that file, given the difficulty of (3) & (4)?
I think picking names too early is at best a minor annoyance, and at worst a pretty major distraction.
- You have to use that early name to open that file later to make changes.
- The process of assigning a name and referencing it repeatedly puts a damper on changing the idea “too far” from the original idea and original name.
- If that name is utilized in a URL or shared with anyone or (worst of all!) gets linked from other documents, changing it means changing everywhere it might be linked from. This problem is hopeless if we permit our friends and coworkers to retain private documents/bookmarks/etc. Even considering shared workspaces, frequently it isn’t even possible to enumerate such places. (I’m looking at you, Google Docs.)
One alternative is:
cat >> ~/to_file/$(uuidgen) << EOF
my super clever thought
EOF
This is slightly unsatisfying, too: MacOS tracks update timestamp, not creation timestamp, by default. So we maybe want a separate “meta” file here, if the creation timestamps are important. But we can tackle it with either discipline (never update!) or a small bit of extra complexity, like
U=~/to_file/$(uuidgen)
date +"%s" > ${U}.created_at
cat >> ${U} << EOF
my even more clever thought
EOF
With even that tiny bit of infrastructure in place, we can generate a timestamped log of “recordings” about whatever is useful to you!
The access pattern is kinda interesting here.
Obviously, we don’t want to – and won’t, or at least shouldn’t – remember the raw UUIDs.
So we need to search, instead.
We can use something like ag
:
~/to_file ➜ ag clever
D5FF7ADF-347B-4F12-BEEF-57A15725BE88
1:my even more clever thought
8319D617-59AE-4369-85C1-D5A738C91ABD
1:my super clever thought
Why bother with uuidgen
?
- I have built some very small systems on similar ideas but with much shorter “token generation” schemes; the problem here is eventually they conflict, and you either lose data (perhaps unknowingly), concatenate entries (perhaps unknowingly), or need to implement an existence check.
- In the case of a shared folder (like Dropbox), the existence check can’t check whether records already exist on a “replica” (ie your personal laptop) that hasn’t been synced yet.
- It’s built into MacOS, so there’s no custom token generation code to write.
This is conceptually kinda similar to the technique of Write-ahead logging:
The ~/to_file
directory functions as our “log” (of “thoughts” or “recordings” or whatever), which is to be reconciled later by moving the file into a more appropriate place.