best practice

what is the best way to clean currenty programmed sw?
I think aboul loading an empty project(only setup and loop)
there isn't a clean button!
My problem is I'm a newbie and I'm trying a lot of code samples and hardware configurations.
what appen if my last programmed project use a pin for output and the next project use the same pin as input (that could short circuit the pin).
I mean that if I configure new hardware before programming the board when i connect usb cable to Arduino the program start and can cause this type of problem.
Is better to program arduino unconnected and then wire the external circuit or clean the board (remove program) before changing hardware (based on default configuration of all pins as input) connect new hardware an then reprogramming new code?

I think the first option (claning the project) is the best because I don't program the board every day and could be difficult to remenber last programmwed sw.

Even if there was a "clean" option, you'd still want to "clean" it anytime you use it. So instead, just upload the "Blink" sketch before you attach any hardware. Then you'll always be starting from a known state.

I always program the board first, then plug the circuit in.

Whenever I'm done with a project, I will always reload a Blink sketch (pin 13) onto the board I was using to prototype on. This prevents a scenario where you leave it with something programmed and some time down the road you wire it up completely different and cause some really odd things to happen with your circuit, possibly short circuiting things. If the next time I use the board, pin 13 isn't blinking, I know I either left something on it that needs to be cleared first (and I will beat myself over that), or somehow the board is dead.

My habit is after working on a sketch that used external components is to remove the component wiring or shield and load the blink sketch onto the board. That way the next time I power up the board and see the blinking pin 13 I know it's safe to attach any shield and work on the next project. If I don't see pin 13 blinking, I just reload the blink sketch just to make sure there isn't some sketch running on it that might be manipulating I/O pins. With my 5 or 6 various arduino boards it would be rather risky leaving prior sketches in them. Any project that I plan on keeping, I convert to a standalone 328 chip that solders to the external components and modules used in that project.