22
My kid asked why my code was so long and it made me stop
I was showing my eight-year-old a simple number guessing game I wrote in Python. It had about forty lines. She looked at it and said, 'Why is it so big? Can't you just tell the computer to guess?' I explained loops and conditionals, but her question stuck. I realized I was writing for other coders, not for the simplest idea. I rewrote it to just ten lines by using a while True loop and one if statement. Has anyone else had a simple question make you rethink a basic approach?
3 comments
Log in to join the discussion
Log In3 Comments
gracea191mo ago
Ever read that thing about how kids ask the best questions because they don't know the "right" way to do stuff? Your story totally fits. It's so easy to add extra code just because it feels like the normal way to write it. Makes you wonder how much of our own work is just habit, right?
5
butler.abby18d ago
I actually see it a bit differently lol. I think that extra code and comments exist because real world code has to handle edge cases and future devs who might not know the context. Kids ask great questions but they don't account for things like error handling, security, or making sure the system works when something unexpected happens. The ten line function might look clean, but the three line version probably crashes on Tuesdays when someone passes in a null value.
6
janab821mo ago
Yeah, that part about writing code for other coders really hit me. I used to add extra checks and comments just because that's how I was taught. After reading @gracea19's point about habit, I see my old ten-line functions were often just three lines of actual work. The kid's question cuts right through all that.
4