I should explain what I mean by a close-in obstacle. It's the 50' tree at the end of a 2500' strip. Using TO flaps will get you airborne and climbing in less distance, and you will clear the tree with greater margin. In this case, using TO flaps would be the "right" way.
In another example, if we have a 3000' ridge 10 miles from an airport where runway length is not a factor. Imagine two identical airplanes starting their TO roll side by side, one with TO flaps, one clean. The flapped airplane will become airborne earlier and will begin its climb out. The clean airplane will take off farther down the runway, and will for a short time be lower than the flapped airplane. However, the clean airplane will accelerate more quickly and soon be out-climbing the flapped airplane and it will be covering more ground with a cooler engine while doing so. If the clean airplane isn't already higher by the time of flap retraction, it will be as flaps are retracted. It doesn't matter if the flaps come up slowly or in the blink of an eye; the airplane will need to accelerate, and sacrifice climb in doing so. The airplane that took off clean will cross the ridge sooner and with greater margin. In this case, taking off clean (assuming your POH allows it; mine does) would be the "right" way in my mind.
Some of this may seem counter intuitive, but you have to remember that climb performance is based on excess power or thrust, not excess lift. The additional lift provided by the flaps gets us airborne sooner. But once airborne, the flap's additional drag reduces excess power/thrust and degrades climb performance.