How Can I Improve My Coding Discipline While Working on Projects?
Asked by
CodingNinja47
I've been diving into Python and I'm currently working on a project that I want to include on my CV. As I code, I often end up rewriting sections because I think of new ways to structure itโlike realizing a function might only be used once and then deciding to change it. I'm looking for a more disciplined approach to coding so I can avoid feeling like I'm just wasting time. I tried mapping things out on paper first, but I find that a lot of ideas come to me once I start coding. Are there any resources or strategies that can help me plan better or create a proper roadmap? Autocomplete features in VS Code also distract me, which doesn't help either.
Answers
To address your question on being disciplined, consider delaying the extraction of functions or classes until you've actually got duplicate code or data that needs optimizing. This way, you're focusing on making changes that matter rather than getting sidetracked with premature optimizations.
Reply to this answer
A technique that's really useful is to jot down TODO comments as you code. For instance, if you see a function that could be improved later, just write a comment like `// TODO: refactor these functions into classes.` This keeps track of things you want to revisit without interrupting your workflow right now. You'll find doing this helps keep your code cleaner while allowing you to focus on immediate tasks.
Reply to this answer
It's totally normal to feel the urge to refactor your code as you're writing it. Instead of suppressing that instinct, try to embrace it. Youโll gradually develop a knack for structure as you gain experience. Each time you refactor, you're actually learning something valuable! So, if you find yourself fixing things multiple times, donโt worryโby your tenth project, itโll feel more intuitive and youโll refactor less often.
Reply to this answer
One way to improve your coding discipline is to create a requirements specification before you start coding. This means writing down all the features and use cases you want to implement. It helps you think through edge cases early on, which saves you from making major changes later. Sure, you might still get new ideas while coding, but having a solid plan makes it easier to handle any changes that come up.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions