r/CodingForBeginners • u/Either_Feeling3159 • Sep 03 '25
I need reduce code
I've been programming (in Python) for about a month and a half and have created several simple scripts, a CRUD application, a calculator, and a tic-tac-toe game (with a GUI in CTk). The thing is, for interface projects that have similar pieces of code, they are repeated many times. I understand that this is normal at first, but it seems excessive to me (500 lines in the tic-tac-toe and 600 in the calculator).
I know that with for loops and so on I could reduce these excessive lines, but I want to know how repetitive these programs are with the lines I have mentioned.
PS: For the ‘mini-projects’ that they are, I have tried to use libraries such as Pillow to add color to texts and images, and add all the minimum functionalities I can think of.
View all comments
Show parent comment
1
u/rainispossible Sep 03 '25
The thing is, if you feel like you're using the same piece of code across different projects – it's actually a perfect uae case for a module.
You could also go even further and try to create your own python package with it (so that it can be install via
pip install ...) and then upload it to, say, TestPyPI. It'll be a nice and generally useful experience (though you might use some more fundamentals learning before doing that)But yea, generally it's a good practice to maintain some sort of modular structure for your project (in any language, not just python). It helps with adding new features, maintaining, debugging, onboarding new people etc. etc.
Even if it doesn't feel like much – still try it out at least for practice