How do you decide whether to refactor or rewrite?

Assuming you have an existing codebase and are running into problems due to using the wrong approach. Maybe your product significantly changed since initially building it.

How do you decide whether to refactor, or completely rewrite?

I don't have a specific codebase in mind, so if you answer is "it depends", please use your own codebase as an example rather than asking about mine 😄

I never rebuild/rewrite an entire product - ever - it's bad and Netscape as well as others failed because of it. I try to refactor and evolve based on user feedback. A button no one ever uses doesn't need to work.

Related material:

DHH actually did follow Spolsky for 7 years and only after running out of ideas and constantly hitting brick walls they started investigating a rewrite to rejuvenate the product based on new ideas that weren't around when they first built it. I guess, the answer is, rebuild only if you can't build your new ideas anymore and you can't attract new customers. (He calls it becoming japan in the talk.)

Uff. Difficult question, but certainly ripe for discussion.

I can pull out #dotcolors as an example. I'm currently planning a rewrite for it since I like the product idea, but the code base was pretty experimental and the structure has just gotten. Uh. Wild.

Generally I tend to refactor if I'm happy with the overall structure of the project. Then I just pick out single features and refactor that. On the other hand when I feel that a codebase becomes confusing and unmanageable for me I tend to be pretty harsh with rewriting.

That sounds about right.