H
6

I kept messing up my loops until I tried this trick last month

I was working on a small game in Python and my character kept moving wrong. For three days, I couldn't figure out why the loop kept running after the game was over. I finally wrote each step of the loop on a piece of paper with a pencil, checking the value of my variable after each turn. Seeing it on paper showed me I was using 'while' when I needed 'for'. Has anyone else found that writing code out by hand helps spot mistakes?
3 comments

Log in to join the discussion

Log In
3 Comments
seth_green85
Oh man, that's the oldest trick in the book and it still works. It's like how you remember a grocery list better if you scribble it down instead of typing it. Something about the physical act makes your brain slow down and actually see what's in front of you. I still sketch out logic flows on a napkin when I'm stuck.
5
riverp37
riverp373mo ago
Wait, isn't it the physical act that helps, not just slowing down?
1
margaretf40
It's actually both... the physical act and the slowing down. Writing it out forces you to trace through the logic step by step, but the muscle memory of scribbling on paper does something different in your brain than typing. I've done the same thing with index cards for complex if-else chains, laying them out on my desk like a flowchart. The grocery list example is spot on though... I'll remember a function flow better if I sketched it with a pen than if I highlighted it in an IDE.
3