Refactoring workflow for 200-300 lines of code

I’m having a hard time figuring out a good workflow for this scenario. I’ve found that with OOP (and this is maybe a skill issue), it is a lot faster to violate conventions, get the functionality working on the lowest level of abstraction and then refactor so it’s not dogshit code before moving to the next level of abstraction or other part of the feature.

However, I haven’t been able to figure out a good workflow for consistent refactoring. I’ve tried with /edit extensively but it just does not work well. I have tried with varying level of detail in prompts but in all cases it ends up picking and choosing what to implement. For example, I might have a bunch structural changes I need to make like breaking up bloated classes/methods but if I include in the prompt that type hinting should also be added, /edit just adds the type hints and ignores all my other requests. In this example, I could of course just do it in 2 separate prompts but in most cases the various changes I want to do are coupled so it’s very difficult to split it up into multiple tasks/prompts.

I’ve had other cases where 1/3 of the changes get implemented resulting in completely busted code. Often times it will also delete entire methods and not implement anything to ensure the removed functionality is still present in the refactored version.

Conceptual changes like using a different design pattern instead of an existing one are a complete no go. Usually ends up with half the file being deleted and the implementation is never satisfactory.

My dream scenario is that I can pass a detailed prompt and get the refactoring 90% there with me fixing some bugs afterwards. Is it possible?

1 Like

Not sure if this would work but you could comment out functions you want refactored with header comments that detail how, and then /edit in chat with an instruction to carefully follow the comments in the file to revise the commented out functions in great detail, do not insert // implement x,y,z, etc

Before doing this I would set up a set of unit and integration tests (or have cursor do this for you).