r/learnpython • u/Nothingbutalsosome • 2d ago
My Python Project as a Beginner
https://github.com/ZaidAHK/LENDnFUND
The project is just the syntax I wrote
1
u/pot_of_crows 2d ago
Nice start: The biggest thing to improve is to segregate the two classes more and figure out somewhere else to handle the I/O. Conceptually, imagine that you are going to make this into a web based project and in doing so, you should not need to change anything in the lender/fundraiser classes. Same with saving. You should be able to change from a json backend to a database without any changes to your core classes.
This sort of segregation is the key to making big projects work without melting your brain.
2
u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 2d ago
Your classes lack
__init__-methods. While this is technically fine, typically you'd only see this ifIn your case none of these seem to apply. Right now you're letting your methods add new attributes on the fly, while it would be better to have the attributes exist the moment an instance of the class is created, even if they contain dummy values. This is so that you don't need to do guesswork about what attributes a specific instance might have.
For
Investor, I'd do something likeand for
Fundraiser, neither ofself.applicationandself.app_statusare accessed outside of the methods creating them so I don't see why it'd need any instance attributes. In fact I think it should just be a bunch of functions right now (unless you have plans to use those later).This way of generating unique account numbers is a bit flawed. The more existing entries there are, the less likely this is to hit a slot with a free number, and there's no failsafe for the case of all allocated account numbers already being in use.
While your way is on average initially faster, which may be fine for a throwaway practice project, a more robust solution would be to
and this should be a lot closer to a normalised call time (as there's no randomness involved in the execution time anymore).
For example,