An oldie but goodie...<p>The only exceptions I can think of are:<p>1) The state of the art has fundamentally changed. In this case you are not actually <i>re-writing the same thing</i>. Rather, you are writing something new that obsoletes the old thing. For example, one might replace a string matching based spam filter with a Bayesian spam filter.<p>2) The architecture is fundamentally different. For example, you might have to rewrite to port a piece of high performance computing code from MPI to GPGPU, or to make something single threaded aggressively multi-threaded. It might require a whole new approach to the problem.<p>3) I do believe that there exist code bases that are <i>so fracking gawd-awful</i> that there is nothing to be done with them but take them out behind the barn and shoot them in the head. But these are in the minority, and usually they never worked well or established any kind of "market leading position" to begin with. (If they did, it must not have been a crowded market.)