I've been reading Stack Overflow on 
whats-the-benefit-of-object-oriented-programming-over-procedural-programming
<http://programmers.stackexchange.com/questions/120019/whats-the-benefit-of-object-oriented-programming-over-procedural-programming>
  

It is a good (although not the best) overview of why OO was created and how
it can help organize and reduce errors on large cohesive projects.
With my advance apologies to the "oh here we go again on OO vs Proc" crowd,
I think this question needs to be asked as I personally have not really seen
the side of the question I am about to ask addressed in a clear decisive
manner.

So here we go... HTTP is request/response protocol, so I do not see
procedural programming approach to the web as being necessarily handicapped
when OO vs Proc is considered.  So my question is:  What drives OO
frameworks, such as ZF2/3 to be object oriented?  

In defense of Proc:
        Example:  for each HTTP request, each individual web page to be seen 
inside
the browser can be written as its own mini-MVC structure just using straight
PHP without the "burden" of OO, Design Patterns, etc.

        Granted, this sounds a little basic.  But before one protests 
prematurely,
a lot of the "ugly thorns" of procedural programming can be taken care of. 
i.e database/model connector part can be shared among all the
per-page-scripts, any code duplication, validation, etc, can be moved out
into a functions library, views are separated, and you can still write
function tests, use test driven development and so on and so forth. 

        Granted, to write good procedural code one needs to be well organized 
and
"behave".  Procedural code does not have to be spaghetti code. It can be
clean, awesome, and well-separated.  This separation needs to be enforced by
the programmer and the programming team, opposed to the language constructs
themselves.  Doing so placed a tad more burden on the programmer, i.e. each
script will need to be maintained by the programmer and the programmer will
need to be conscious of what code needs to be changed where, in order to not
write themselves into a tangles of spaghettiness.  Things such as data
validation/cleaning, variable output, and so on will require better
organization and code self-disciplining skills on the part of the programmer
to not mess those up.  In the end, if you apply some solid organization
skills and a good directory structure, you can write procedural code that is
modular, flexible, secure, and high performing.  

My main point is this:  OO, with its encapsulation, and so on, is not really
needed when we are dealing with "writing small scripts, one script for each
page for HTTP's Request/Responce protocol", even when it comes to large
projects.  
And since you are dealing with an individual page requests, the execution
scope is small, heck you can even use global variables in the scripts, not
that I'd recommend it, without fear of them clashing with globals in the
other scripts - that is, natural encapsulation is already happening with
procedural approach to HTTP at per-page level, without the need for OO. 

So what is it about the need for OO that drives OO frameworks such as ZF2?  
Why not spend more time on organizing the programmer instead of organizing
the tool?  
Learning good organization skills is hard.  But so is learning OO.  Why not
invest in better programmers, tutorials, classes, rather than the tools?  Is
the driver behind OO frameworks more that there will always be disorganized
programmers no matter what tools you use, so might as well write a better
tool?

Because, I don't think that OO is "just another flavor" of doing things in
programming.  It is more of a way to organize the programming tool available
to the programmer.

In the end, is OO here just to "put/enforce some organization on fellow
programmers, who otherwise would be too tempted/lazy/ignorant to abuse
freedoms and powers of procedural code to create bad code"?
Or is there any other real good solid reason for using and needing OO?  




--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/What-are-the-benefits-of-OO-vs-procedural-programming-for-the-web-tp4661285.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to