Server programming

koranthala koranthala at
Tue Mar 3 09:08:57 CET 2009

On Feb 24, 1:02 am, Bruno Desthuilliers
<bdesth.quelquech... at> wrote:
> koranthalaa écrit :
> > Hi,
> >       Is server programming in Python procedure oriented or object
> > oriented?
> It's how you want it to be.
> >       I have this question because lately I am asked to make a medium
> > complex web program (extremely database oriented) using Django. When I
> > used to do application programs earlier (in Python itself),  the whole
> > thing being object oriented came out easily in programming. So, I was
> > able to use different patterns etc for programming and the whole thing
> > was - quite fun to design and create.
> >       But when I program in Django, since I just have to work on user
> > responses - everything else being taken care of by Django - only, the
> > complete coding has become procedure oriented. It is not kludgy or
> > anything, but it doesnt have the nice feeling that we get when we code
> > a proper object oriented program.
> So you may want to learn to enjoy the nice feeling we get when we code a
> proper procedural program - or a proper functional one FWIW !-)
> There's nothing inherently wrong with procedural programming. Nor with a
> mix of procedural, OO and functional code - which is usually the case in
> Python. It's just a matter of using the right tool for the problem to
> solve.
> >       Is my coding in error here?
> Don't know - I don't have access to your code. But my experience with
> Django is that I tend to have quite a lot of code in models and
> templatetags, and much less in the views themselves. So I wouldn't say
> that "Django takes care of everything else". If you really ends up
> writing pages upon pages of repeting procedural code in your views and
> nothing in the other parts of the app, then yes, there might be
> something wrong - probably a case of AnemicDomainModel, and possibly a
> lack of knowledge of the whole framework. One of the reasons views are
> usually implemented as functions is that in most cases, you shouldn't
> have a need for more. FWIW, you sometimes don't even need to write a
> specific view - Django's GenericViews can handle quite a lot of cases
> Note also that Django doesn't _require_ that you use functions as view
> handlers - any callable object will do. But given how the HTTP protocol
> works and how Django is designed, there's more often than not just no
> *need* for a custom callable object.
> And finally, as Steve already mentioned, OO is first about objects, and
> that's what you're dealing with in your views - request objects, session
> objects, model objects etc...
> > This is infact my first web program,
> > so it might be the reason. What does other people find? Does web
> > server programming using web frameworks (Django, TurboGears etc) make
> > it procedure oriented?
> Not necessarily, no. Some frameworks requires your request handlers to
> be methods of classes FWIW, and nothing in Django prevents you from
> doing so if you want.
> > If I am in the wrong, it might be due to a
> > wrong design or mindset, and I would like to change it.

Hi Bruno,
   After reading your email, I tried reworking my code so that most of
my logic moves to Models.
   But, most probably because this is my first application
development, I am unable to do so.
   For example:
    I have Models A,B, C, D . Now, there is not much model specific
code (preprocessing before updating code inside Models)in it. Rather
most of the code is of the format:
     data received and to be added to D. But for adding to D, check
whether it is already in C - if not add to C and B. etc...
   Now, I tried putting this code inside Model D,but it does not seem
to belong there - since it modifies other Models.

   Is keeping such code inside views against Django's/Application-
Developments philosophy? In that case, where will this go?

More information about the Python-list mailing list