| | |
Classes vs Functions
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: May 2008
Posts: 11
Reputation:
Solved Threads: 0
OK, this may be a dumb question but I'll ask anyway. I am starting to see the benefits of using classes. Most notably code reuse, inheritance and overloading. Shoud I still be writing fuctions in my scripts or do classes make them obsolete? Is there a rule of thumb that if your script has say 20 lines or more you should write a class?
Classes don't make functions obsolete. The beauty of Python is that you can go either way. It's up to you, if a class makes sense, use it. I use classes in most GUI programs, using inheritance is very common. Also, the program looks more organized and simply makes life easier.
May 'the Google' be with you!
I find functions still a great thing to have if you want to have something unrelated to either class. Personally i like to only have related functions in a class and if i want a function and there is no specific class that it fits into then i do not put it in a class and leave it out.
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Check out my Site | and join us on IRC | Python Specific IRC
![]() |
Similar Threads
- need help writing pseudocodes that involves class and functions (C)
- How do i do chat program using MFC (Microsoft Foundation Classes) and Visual Basic? (Visual Basic 4 / 5 / 6)
- Passing arrays of objects to functions (C++)
- User defined functions (C++)
- Double Linked Lists and Functions required (C++)
- Need help with Const, Ref and Classes. (C)
- The difference between functions and templates? (C++)
- Classes (C++)
Other Threads in the Python Forum
- Previous Thread: Passing varyables through a text file
- Next Thread: Parsing in Python
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied advanced argv beginner change code command convert csv cursor def dictionary digital dynamic dynamically editing enter event examples excel file float format frange function google gui homework i/o import input jaunty java keyboard lapse line linux list lists loop microphone mouse movingimageswithpygame newb number numbers obexftp output panel parameters parsing path port prime programming projects py2exe pygame pygtk pyopengl pyqt python random recursion remote return reverse scrolledtext session simple skinning smtp sprite stderr string strings strip subprocess syntax table tennis terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode unit urllib urllib2 variable voip web-scrape windows wxpython






