n
8

Got some hard feedback on my first project and it actually helped

I showed my first little Python script, a simple number guesser game, to a friend who codes. He said 'Your code works, but it's one big block of text. If you need to change the rules later, you'll have to dig through the whole thing.' I mean, he was right. I had everything in one main function that was like 50 lines long. So I spent last weekend breaking it up. I made separate functions for getting the user's guess, checking if it was right, and even for the welcome message. It took me a few tries to get the variables passing between them right, but now it's way cleaner. I can see how to add a hint system without messing up the core game. Has anyone else had that moment where splitting things into functions finally clicked for them?
3 comments

Log in to join the discussion

Log In
3 Comments
elizabeth875
Honestly I used to think splitting code was just extra work for no reason. But then I had to fix a bug in my own messy script and spent an hour just finding the right spot. After that, functions made total sense.
8
eva_thompson10
Was it weirdly satisfying when you got it working after splitting it up? My first time with functions was a mess, I tried to make a text based adventure. I had the same huge block of code for everything, and adding a new room broke the whole game. Breaking it into little pieces felt like untangling a knot, so frustrating at first but then it just made sense. Now I can't even look at a long function without wanting to chop it up.
4
charlie_allen
Untangling a knot" seems a bit much for some code.
4