[Tutor] Old School

Tim Golden mail at timgolden.me.uk
Fri Apr 11 15:45:49 CEST 2008


Dinesh B Vadhia wrote:
> I belong to the Old School where getting my head around OO is just one big pain.  
> I write software by modularization executed as a set of functions - 
> and it works

The great thing about Python is that you can use Classes if you want,
or not if you don't. I use them less them more as a rule, but it will
depend on what your background is, what model seems best to fit
the problem domain, and so on.

The great thing is that Classes *aren't* second-class citizens in Python
(as though added on as an afterthought), but nor is straight procedural
prgramming. If you're happy writing code like this:

def abc ():
  return [1, 2, 3]

def xyz (list_of_stuff, n):
  return [x + n for x in list_of_stuff]

# then do it. But don't feel that you can't mix that with, eg:

class X (object):
  def __init__ (self, some_list):
    self.some_list = some_list
  def add_n_to_list (self, n):
    self.some_list = xyz (self.some_list, n)

x123 = X (abc ())
print x123.some_list
x123.add_n_to_list (3)
print x123.some_list

Entirely contrived, of course, but nothing wrong with it
as far as it goes.

TJG


More information about the Tutor mailing list