Is It Normal to Rewrite the Same Function Several Times Before It Makes Sense?
Asked by
wavelength.580
I'm still learning to program, and I often rewrite the same function multiple times before I feel like I truly understand it. I'll get something working, then revisit it the next day and completely restructure it because I finally understand what I was trying to accomplish. Is this a normal part of learning, or does it mean I'm unusually slow at internalizing concepts? Are there practical ways to make ideas stick faster and reduce the rewrite cycle?
Answers
For optimization, itโs often useful to start with a straightforward version that lists the steps clearly. After it works, look for ways to improve the flow or reduce unnecessary work. That kind of iterative refinement is a normal part of developing a solution, not a sign that you failed the first time.
Reply to this answer
Rewriting isnโt necessarily wasted effort. Each version can deepen your understanding of the algorithm and the problem itself. Even experienced developers revisit code, and sometimes several rounds of changes eventually lead almost back to the original solution. The important part is what you learn during the process.
Reply to this answer
Thatโs completely normal. A useful habit is to write one sentence explaining what the function should do before you start coding. If you canโt describe its purpose clearly, that usually means the problem needs more thought first. Defining the goal up front can make the later rewrites much smaller.
Reply to this answer
A rough plan can help. Before coding, sketch the steps or draw a small diagram, then add comments describing the functionโs purpose, inputs, limitations, and reasoning. Keeping the โwhatโ and โwhyโ separate from the implementation makes it easier to experiment with the code without losing the original goal. Once the design is settled, you can remove temporary notes.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions