9
I used to write my code in one big file, now I split it up
When I first started learning Python about a year ago, I wrote everything in a single script. My first project was a simple number guessing game, and the whole thing was over 200 lines in one messy file. I thought it was fine because it worked. Then I tried to add a high score feature and got totally lost in my own code. I spent more time scrolling than coding. A guy in a tutorial video said, 'If your file is longer than your screen, break it up.' That stuck with me. Now I put my functions in one file, my main game loop in another, and my data in a third. It's so much easier to find things and fix bugs. How do you guys decide when to split your code into different files?
3 comments
Log in to join the discussion
Log In3 Comments
rose_cooper13d ago
Ever think about how splitting files helps when you work with someone else? I got stuck once because my partner's giant file kept causing merge conflicts in git. Breaking things into modules meant we could each edit separate parts without breaking the whole thing. That story from @miamitchell about the 3000-line script sounds like a nightmare for version control. For me, if a piece of code has one clear job, like handling user input, it gets its own file.
3
miamitchell14d ago
My buddy's first Unity project was one 3000-line script. Took him 20 minutes just to load it in the editor.
2
milestaylor1d ago
Remember my first web project? One HTML file with all the styles and scripts crammed inside. Tried to change the font color and broke the whole login button. Took me three days to find the missing bracket in that mess. Splitting things up felt like cleaning a hoarder's garage, but suddenly everything had a place.
4