Server programming

Discussion in 'Python' started by koranthala, Feb 23, 2009.

  1. koranthala

    koranthala Guest

    Hi,
    Is server programming in Python procedure oriented or object
    oriented?
    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.
    Is my coding in error here? 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? If I am in the wrong, it might be due to a
    wrong design or mindset, and I would like to change it.
     
    koranthala, Feb 23, 2009
    #1
    1. Advertising

  2. koranthala

    Steve Holden Guest

    koranthala wrote:
    > Hi,
    > Is server programming in Python procedure oriented or object
    > oriented?
    > 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.
    > Is my coding in error here? 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? If I am in the wrong, it might be due to a
    > wrong design or mindset, and I would like to change it.
    >

    It's just that Django *seems* procedure-oriented because your views are
    written as functions. But they take request objects as arguments and
    return response objects as results, so the framework is object-oriented.
    Also each model is a class, and querysets eventually yield lists of
    instances.

    I wouldn't worry too much until Django forces you to do somethign you
    really don't want to do ...

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC http://www.holdenweb.com/
     
    Steve Holden, Feb 23, 2009
    #2
    1. Advertising

  3. koranthala a é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.
     
    Bruno Desthuilliers, Feb 23, 2009
    #3
  4. koranthala

    koranthala Guest

    On Feb 24, 1:02 am, Bruno Desthuilliers
    <> 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?
     
    koranthala, Mar 3, 2009
    #4
  5. koranthala a écrit :
    (snip)

    > 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...


    And you don't find it "model specific" ? Man, this is business rules,
    and as such belongs to the models part, not to views. You surely want to
    make sure these rules always apply, don't you ?

    > Now, I tried putting this code inside Model D,but it does not seem
    > to belong there - since it modifies other Models.


    And ? Who said a Model (or ModelManager) shouldn't touch other models ?

    > Is keeping such code inside views against Django's/Application-
    > Developments philosophy?


    FWIW, I see this antipattern (AnemicDomainModel) way too often in django
    apps. This doesn't make it less of an antipattern.

    > In that case, where will this go?


    It's impossible to say exactly where in the models module without a
    sufficiant knowledge of the domain, rules etc. Sorry, but my crystal
    ball is out for repair.
     
    Bruno Desthuilliers, Mar 3, 2009
    #5
  6. koranthala

    koranthala Guest

    On Mar 3, 8:09 pm, Bruno Desthuilliers <bruno.
    > wrote:
    > koranthala a écrit :
    > (snip)
    >
    > > 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...

    >
    > And you don't find it "model specific" ? Man, this is business rules,
    > and as such belongs to the models part, not to views. You surely want to
    > make sure these rules always apply, don't you ?
    >
    > >    Now, I tried putting this code inside Model D,but it does not seem
    > > to belong there - since it modifies other Models.

    >
    > And ? Who said a Model (or ModelManager) shouldn't touch other models ?
    >
    > >    Is keeping such code inside views against Django's/Application-
    > > Developments philosophy?

    >
    > FWIW, I see this antipattern (AnemicDomainModel) way too often in django
    > apps. This doesn't make it less of an antipattern.
    >
    > > In that case, where will this go?

    >
    > It's impossible to say exactly where in the models module without a
    > sufficiant knowledge of the domain, rules etc. Sorry, but my crystal
    > ball is out for repair.


    Thank you, Bruce.
    Sorry for the rather naive questions.
     
    koranthala, Mar 3, 2009
    #6
  7. koranthala a écrit :
    > On Mar 3, 8:09 pm, Bruno Desthuilliers <bruno.
    > > wrote:
    >> koranthala a écrit :
    >> (snip)
    >>
    >>> 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...

    >> And you don't find it "model specific" ? Man, this is business rules,
    >> and as such belongs to the models part, not to views. You surely want to
    >> make sure these rules always apply, don't you ?
    >>
    >>> Now, I tried putting this code inside Model D,but it does not seem
    >>> to belong there - since it modifies other Models.

    >> And ? Who said a Model (or ModelManager) shouldn't touch other models ?
    >>
    >>> Is keeping such code inside views against Django's/Application-
    >>> Developments philosophy?

    >> FWIW, I see this antipattern (AnemicDomainModel) way too often in django
    >> apps. This doesn't make it less of an antipattern.
    >>
    >>> In that case, where will this go?

    >> It's impossible to say exactly where in the models module without a
    >> sufficiant knowledge of the domain, rules etc. Sorry, but my crystal
    >> ball is out for repair.

    >
    > Thank you, Bruce.


    s/ce/no/ !-)

    > Sorry for the rather naive questions.


    No problem. And these are not "naive" questions FWIW.
     
    Bruno Desthuilliers, Mar 4, 2009
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UGVyZG8=?=
    Replies:
    0
    Views:
    601
    =?Utf-8?B?UGVyZG8=?=
    Feb 6, 2004
  2. Matt
    Replies:
    35
    Views:
    10,733
    George Neuner
    Jul 22, 2004
  3. -
    Replies:
    2
    Views:
    447
    Alan Krueger
    Jul 29, 2005
  4. Casey Hawthorne
    Replies:
    4
    Views:
    1,051
    Jarek Zgoda
    Aug 4, 2006
  5. Joe Mayo
    Replies:
    168
    Views:
    3,497
    David Thompson
    Oct 22, 2007
Loading...

Share This Page