Using Classes

geremy condra debatem1 at gmail.com
Fri Jun 25 03:00:49 EDT 2010


On Thu, Jun 24, 2010 at 9:04 AM, Alf P. Steinbach /Usenet
<alf.p.steinbach+usenet at gmail.com> wrote:
> * Mag Gam, on 24.06.2010 13:58:
>>
>> I have been using python for about 1 year now and I really like the
>> language. Obviously there was a learning curve but I have a programing
>> background which made it an easy transition. I picked up some good
>> habits such as automatic code indenting :-), and making my programs
>> more modular by having functions.
>>
>> I know that Python is very OOP friendly, but I could not figure out
>> why and when to use Classes in it. I mostly use it for simple text
>> parsing  I suppose when a program gets "complicated" I should start
>> using Classes. Are there any tips or tricks people use to "force" them
>> into the OOP mentality? I would like to force myself to learn the
>> Python way but so far I could not figure out WHY I would need a class
>> for this...
>
> Use whatever paradigm that yields code that you easily understand. <g>
>
> Having said that, the main use of a class is to model some data with an
> associated set of operations.
>
> For this a class is merely a convenience, but sometimes the convenience can
> be so great that any other approach would be impractical in comparision.
>
> In some cases a non-class approach ends up with a number of routines foo,
> bar, zlopf etc. that all take some argument of a "general" type and all
> internally has some "if it's really a BRACHYKLURB, do A, assuming that it
> has BRACHYKLURB-specific data, but if it's really a KNETCHOFICHUS, then do
> B, assuming that it has KNETCHOFICHUS-specific data, and as default, if it's
> none of those, do C".

If making up words is an art form, we are in the presence of a master.

/applause

Geremy Condra



More information about the Python-list mailing list