943,884 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 1883
  • Python RSS
Nov 20th, 2008
0

Classes vs Functions

Expand Post »
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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ccandillo is offline Offline
16 posts
since May 2008
Nov 20th, 2008
0

Re: Classes vs Functions

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.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Nov 21st, 2008
0

Re: Classes vs Functions

I use a class 99% of the time. Once the program gets beyond the simple function level, it organizes the code IMHO. Also, a class doesn't have any of the global variable problems.
Reputation Points: 741
Solved Threads: 692
Nearly a Posting Maven
woooee is offline Offline
2,305 posts
since Dec 2006
Nov 21st, 2008
0

Re: Classes vs Functions

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.
Reputation Points: 264
Solved Threads: 183
Veteran Poster
Paul Thompson is offline Offline
1,095 posts
since May 2008
Nov 22nd, 2008
0

Re: Classes vs Functions

+1 for Paul & Vega
Reputation Points: 462
Solved Threads: 392
Senior Poster
evstevemd is offline Offline
3,681 posts
since Jun 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Passing varyables through a text file
Next Thread in Python Forum Timeline: Parsing in Python





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC