I've been learning Python and I'm currently working on a project to boost my CV. However, I find myself rewriting my code constantly as I code, rethinking its structure. For example, I might put something into a class or define a new function only to realize later that it's only used once. Is there a more disciplined approach I can take to avoid wasting time on this? I've tried outlining a structure on paper first, but new ideas come up while I'm coding. Are there resources that provide guidance on improving project structure in advance, or tools for creating a solid roadmap? Autocomplete features in VS Code also distract me easily.
4 Answers
Yes, there’s a disciplined way to handle this. Hold off on extracting functions or classes until you see actual duplicate code or data that needs clean-up. This way, you’re making changes based on clear needs rather than whims.
Shift your focus toward planning before you dive into coding. Create a requirement specification document that outlines all the cases and features you want to include. This preparation can help you anticipate edge cases and necessary functionalities without getting caught in the coding loop of continuous rewrites.
Don't stress too much about the impulse to refactor while coding. It’s totally normal! As you gain more coding experience, you’ll develop a better intuition for structuring your code. Remember, every time you refactor is a chance to learn. It might feel like you're redoing things now, but with time, you’ll find you’re refactoring less frequently in future projects.
Instead of trying to fix everything on the spot, consider using TODO comments for ideas that can wait. For instance, if you think something should be refactored, just jot it down with a comment like `// TODO: refactor` near your code. This way, you can come back to it later without getting sidetracked from your current progress. Many editors highlight TODOs making them easy to find later.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically