That's not useful as a rule of thumb, since you can't know the size of "all inactive anonymous pages" without doing extensive runtime analysis of the system under consideration. That's pretty much the opposite of what a rule of thumb is for.
Better overcommit right away and live with the feeling you're wasting space.
Swap file means fallocating, setting extended attributes (like `nocow`), finding file offset and writing it to kernel params, and other gotchas, like btrfs not allowing snapshotting a subvolume with an active swap file.
Technically it's preferable, won't argue with that.
Easier than partitions:
mkswap --size 2G --file swap.img
swapon swap.img