Preventing overwriting of sketch -- What is the best approach?

I'm proof that it is possible. I have a Pro Micro permanently attached to my computer as a "macro keyboard" and I have accidentally uploaded sketches to it several times after selecting the wrong port from the Arduino IDE's Tools > Port menu while attempting to upload to another board.

Instructions for disabling the serial port in Windows are provided here:

It's also possible to disable uploading on the Mega by putting a 10 uF capacitor between the GND and RESET pins, or by cutting the "RESET-EN" jumper on the board: