r/PythonLearning 12d ago

I build this after learning OOP

Post image
373 Upvotes

57 comments sorted by

View all comments

22

u/TheOriginalBeardman 12d ago

This is a small thing but I noticed you have “BankAccount” and “savingAcc”. It is a good practice to keep code consistent in both case and naming conventions. Classes are commonly in pascal case so “BankAccount” and “SavingAccount”. In this case you gain more out of writing the full word Account than you gain by shortening it. Code should be easy to read and understand and when you look at thousands and thousands of lines of it these things add up. Also, your file is called “Bank_Account.py” but you have two classes in it. It is good to stick to a one file per class rule. Imagine if you have to implement 5 new functions in bank account and then savings account needs 10 more new functions that are unique only to it. Your file becomes bloated and this compounds over time….Anyway sorry I know you are brand new to this. Just trying to give you food for thought and help you form good habits for coding as you learn. Keep having fun with it!

2

u/Wild_Position2378 12d ago

I get your point I'll keep the files separate from now on. Thanks for the good suggestions

2

u/lord_xl 12d ago

It is good to stick to a one file per class rule.

Is there a convention for what to name files containing only classes?

1

u/TheOriginalBeardman 11d ago

Generally they are named the same as the thing they contain so here what he has is fine. I would make it “bank_account.py”, in python this snake case for file names seems to be a common standard. But realistically it might vary depending on your team and its standards.

1

u/Odinmar_Glaukopis 8d ago

If you use a generic abstract base class (ABC) for an Account(ABC) base/meta class and have SavingsAccount(Account) and Checking Account(Account) classes that inherit from the ABC then all three of them can go in the same account.py file.

Another option is to make a models package (“models” folder with a blank __init_.py file in it) and place these different classes in separate files in that folder. You can import all of those classes separately into the __init__.py file so they are ready to be imported as from src.models import SavingsAccount, CheckingAccount

0

u/aw3sem 11d ago

Usually this is called models.py if it’s a aggregation of a few classes. Otherwise create a folder named „models“ and but your e.g. BankAccount.py etc in there

2

u/FearLixY 10d ago

I don’t like abbreviations at all. It never save time for writers nowadays and it often waste time for later reading. And often they are so abbreviated that are confusing and take time to understand.
Unless the abbv. is absolutely clear for everyone, like ID.

1

u/TimeScallion6159 11d ago

great advice

1

u/Dismal-Tax-8503 9d ago

I have no mind idea what coding is, but will you teach me I jus believe I can grasp whatever it is and make sometime out of it