FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » OOP versus Procedural/Functional
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
OOP versus Procedural/Functional [message #177556] Mon, 09 April 2012 19:35 Go to next message
Mr. B-o-B is currently offline  Mr. B-o-B
Messages: 42
Registered: April 2011
Karma: 0
Member
I was curious about peoples thoughts in regards to OOP with PHP.

Are there pro's/con's of writing OOP code versus procedural/functional
coding?

Strictly speaking for PHP, I do the bulk of my coding as
procedural/functional. I really haven't found any added benefit to going
the OOP route.

Am I missing something, or is it just a different approach to the same
problem?

Thanks!

Mr. B-o-B
Re: OOP versus Procedural/Functional [message #177557 is a reply to message #177556] Mon, 09 April 2012 19:59 Go to previous messageGo to next message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma: 0
Senior Member
Mr. B-o-B wrote:
> I was curious about peoples thoughts in regards to OOP with PHP.
>
> Are there pro's/con's of writing OOP code versus procedural/functional coding?
>
> Strictly speaking for PHP, I do the bulk of my coding as
> procedural/functional. I really haven't found any added benefit to going the
> OOP route.

There is two minds about OOP, there are those who thinks is the way to go and
those who thinks it don't give any benefits.



> Am I missing something, or is it just a different approach to the same problem?

It's another way to solve the problem and there is a third way which kind of
mixes both worlds.

Read some more about OOP in general and get a bit better insight for example:
http://www.inf.ufsc.br/poo/smalltalk/ibm/tutorial/oop.html

The site may or may not be good, just got it as a hit on google, never read it
myself.

If you get an aha-moment, then OOP maybe is something for you, but if you feel
it's just making things complicated, than stay with traditional functional
programming.

Many of the major big projects uses OOP, so it can be a good point in knowing
how it works.

--

//Aho
Re: OOP versus Procedural/Functional [message #177559 is a reply to message #177556] Mon, 09 April 2012 20:55 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/9/2012 3:35 PM, Mr. B-o-B wrote:
> I was curious about peoples thoughts in regards to OOP with PHP.
>
> Are there pro's/con's of writing OOP code versus procedural/functional
> coding?
>
> Strictly speaking for PHP, I do the bulk of my coding as
> procedural/functional. I really haven't found any added benefit to going
> the OOP route.
>
> Am I missing something, or is it just a different approach to the same
> problem?
>
> Thanks!
>
> Mr. B-o-B
>
>
>
>
>

It is another approach, and like any approach, it has its advantages and
disadvantages.

One of the big advantages is you can put all of your validation code in
the class - for instance, if you have a User class with username,
password and email, the three fields can be validated in the class
itself. This means all of your validation for the three fields is in
one place. The class itself is bigger, but there's less duplication of
code (i.e. you don't have to verify the password when they sign up or
when they try to change their password). Overall, you typically end up
with fewer lines of code and fewer bugs due to the less duplication.

And properly designed, you could take this User class and drop it into
another website unchanged, so you already have all the information
available.

Other advantages are things like isolating database calls from the rest
of the program - put all of your database-specific stuff in a class,
then the class object represents the connection to the database. The
mysqli_xxx interface is a good example of this for MySQL.

You can simulate OO with just functional coding, but you don't get the
full advantages of OO unless you design your code to use OO.

With that said - I like OO, but I still do functional programming also.
Like anything else, neither is best in every instance. Your best bet
is to become familiar with OO and try it out. See where it will work
for you and where it won't.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: OOP versus Procedural/Functional [message #177561 is a reply to message #177557] Mon, 09 April 2012 21:46 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
J.O. Aho wrote:
> Mr. B-o-B wrote:
>> I was curious about peoples thoughts in regards to OOP with PHP.
>>
>> Are there pro's/con's of writing OOP code versus procedural/functional
>> coding?
>>
>> Strictly speaking for PHP, I do the bulk of my coding as
>> procedural/functional. I really haven't found any added benefit to
>> going the
>> OOP route.
>
> There is two minds about OOP, there are those who thinks is the way to
> go and those who thinks it don't give any benefits.
>
>
>
>> Am I missing something, or is it just a different approach to the same
>> problem?
>
> It's another way to solve the problem and there is a third way which
> kind of mixes both worlds.
>
> Read some more about OOP in general and get a bit better insight for
> example:
> http://www.inf.ufsc.br/poo/smalltalk/ibm/tutorial/oop.html
>
> The site may or may not be good, just got it as a hit on google, never
> read it myself.
>
> If you get an aha-moment, then OOP maybe is something for you, but if
> you feel it's just making things complicated, than stay with traditional
> functional programming.
>
> Many of the major big projects uses OOP, so it can be a good point in
> knowing how it works.
>
My research indicated that while it was definitely better for certain
things - VERY large projects being one of them, it wasn't worth the
hassle of doing it on small stuff.

I know of at least one company director who told me 'we wouldnt have
lost the business if we had decided NOT to write it in object oriented
code' By the time they realised the cruciality of proper pre code
object definitions, it was too late and you cant hack OO like you can
procedural.

I think if the project warrants the sort of intense functional
decomposition and 'objectification' process and there are dozens of
coders working on it, its a clumsier but more safe way to get slowly to
a working solution.

Like designing a database, you need to be clear on what objects you are
going to use and what operations you will perform on them and the
impact (relations) you want to have on other objects.

You can use an OO approach without actually using the language
extensions - E.g, in terms of files with defined (function) entry points
and static internal data..

The approach is worth studying: whether you want to force *all* your
code into the mould and/or use OOP language extensions is a moot point.

The step from machine code to assembler is like 100, from assembler to
macro assembler is like 10, from macro assembler to a language like C is
about 1 and from C to C++ is about 0.1 in my opinion.

I.e its a question of diminishing returns every time.






--
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.
Re: OOP versus Procedural/Functional [message #177563 is a reply to message #177556] Mon, 09 April 2012 22:34 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 09.04.2012 21:35, schrieb Mr. B-o-B:
> I was curious about peoples thoughts in regards to OOP with PHP.
>
> Are there pro's/con's of writing OOP code versus procedural/functional coding?
>
> Strictly speaking for PHP, I do the bulk of my coding as procedural/functional. I
> really haven't found any added benefit to going the OOP route.
>
> Am I missing something, or is it just a different approach to the same problem?
>
> Thanks!
>
> Mr. B-o-B

The OOA/OOD way, supported by a selective use of UML, offers one complete path from
requirements to application architecture to implementation.

For the smaller work at hand and a language not complete OO, but with OO extensions,
like PHP, you can choose what suits you best.

Objects are data plus code. I found it quite handy for objects like users, companies,
orders, invoices, etc that correspond to database entities.

/Str.
Re: OOP versus Procedural/Functional [message #177567 is a reply to message #177557] Tue, 10 April 2012 02:29 Go to previous messageGo to next message
Michael Vilain is currently offline  Michael Vilain
Messages: 88
Registered: September 2010
Karma: 0
Member
In article <9ugtdvFqubU1(at)mid(dot)individual(dot)net>,
"J.O. Aho" <user(at)example(dot)net> wrote:

> Mr. B-o-B wrote:
>> I was curious about peoples thoughts in regards to OOP with PHP.
>>
>> Are there pro's/con's of writing OOP code versus procedural/functional
>> coding?
>>
>> Strictly speaking for PHP, I do the bulk of my coding as
>> procedural/functional. I really haven't found any added benefit to going
>> the
>> OOP route.
>
> There is two minds about OOP, there are those who thinks is the way to go and
> those who thinks it don't give any benefits.
>
>
>
>> Am I missing something, or is it just a different approach to the same
>> problem?
>
> It's another way to solve the problem and there is a third way which kind of
> mixes both worlds.
>
> Read some more about OOP in general and get a bit better insight for example:
> http://www.inf.ufsc.br/poo/smalltalk/ibm/tutorial/oop.html
>
> The site may or may not be good, just got it as a hit on google, never read
> it
> myself.
>
> If you get an aha-moment, then OOP maybe is something for you, but if you
> feel
> it's just making things complicated, than stay with traditional functional
> programming.
>
> Many of the major big projects uses OOP, so it can be a good point in knowing
> how it works.

OK. I thought I was missing something by not immediately jumping on the
OOP bandwagon. My first language was FORTRAN and a friend had to tell
me about 'automatic variables' when I had a particularly annoying
problem that worked in FORTRAN but failed in C.

I picked up the php version of OOP because it made more sense to me than
Perl's implementation. There's to much of Perl I have yet to learn but
I was reasonably able to pick up php 4 and php 5's OOP model and get it
working on small stuff. Then I tried to get something bigger (phpBB),
it was an interesting mess of both procedural and OOP.

I stand by the "use what works when needed" rule. Sometimes it's a ball
peen hammer. Sometimes a sledge. Sometimes bazooka.

--
DeeDee, don't press that button! DeeDee! NO! Dee...
[I filter all Goggle Groups posts, so any reply may be automatically ignored]
Re: OOP versus Procedural/Functional [message #177569 is a reply to message #177556] Tue, 10 April 2012 08:14 Go to previous messageGo to next message
Goran is currently offline  Goran
Messages: 38
Registered: January 2011
Karma: 0
Member
On 9.4.2012 21:35, Mr. B-o-B wrote:
> I was curious about peoples thoughts in regards to OOP with PHP.
>
> Are there pro's/con's of writing OOP code versus procedural/functional
> coding?

If you stick with procedural programming you will never get a decent job :D
Re: OOP versus Procedural/Functional [message #177570 is a reply to message #177569] Tue, 10 April 2012 10:06 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 10.04.2012 10:14, schrieb Goran:
> On 9.4.2012 21:35, Mr. B-o-B wrote:
>> I was curious about peoples thoughts in regards to OOP with PHP.
>>
>> Are there pro's/con's of writing OOP code versus procedural/functional
>> coding?
>
> If you stick with procedural programming you will never get a decent job :D

and even kill your self-fulfillment as programmer.

/Str.
Re: OOP versus Procedural/Functional [message #177576 is a reply to message #177569] Tue, 10 April 2012 12:04 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Goran wrote:
> On 9.4.2012 21:35, Mr. B-o-B wrote:
>> I was curious about peoples thoughts in regards to OOP with PHP.
>>
>> Are there pro's/con's of writing OOP code versus procedural/functional
>> coding?
>
> If you stick with procedural programming you will never get a decent job :D

True. Its one of those fashions that everybody has to do, like wearing a
suit at a bank used to be.

No doubt it will pass in time.


--
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.
Re: OOP versus Procedural/Functional [message #177581 is a reply to message #177556] Tue, 10 April 2012 12:49 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Mr. B-o-B)

> I was curious about peoples thoughts in regards to OOP with PHP.
>
> Are there pro's/con's of writing OOP code versus procedural/functional
> coding?
>
> Strictly speaking for PHP, I do the bulk of my coding as
> procedural/functional. I really haven't found any added benefit to going
> the OOP route.
>
> Am I missing something, or is it just a different approach to the same
> problem?

Besides what the others have written, there are some things that I
really like about using OOP in PHP:

* comfort
With PHPDoc comments and a good IDE (e.g. Eclipse/PDT) you can get many
assistance when writing code. You type an object variable, and since the
IDE knows from the comments of what class it is, it automatically
suggests available method names with their descriptions, parameter lists
etc.

* security
You can define access restrictions on methods and member variables and
type hinting on parameter passing, so that PHP can check if a passed
object belongs to a particular class or interface.

And most important for me:

* inheritance/polymorphism
You can easily extend the functionality of a class by deriving a child
class from it. But you can also still use the child class in a context
where an object of the base class is required, without having to change
any code.

I use this in my form classes for example: For all the basic form
controls (input fields, select boxes, password fields, ...) I have my
classes. If I should now need a more special control, e.g. a select box
with some predefined values, I simply derive a child class, add some
other initialization code and that's it. Just a few lines. In every
other context, e.g. when creating the form or processing its data, I
don't have to change anything, I can use the new form control like any
others.

Another example: When I call the output methods of my visual objects
(all the stuff, that represents something on an HTML page), I just have
to make sure the objects are derived from the base class for these
visual objects, because then I know that all derived classes will also
have a render method and be able to output something. I don't have to
know what these objects are and what they represent, I just tell them
"render yourself" and that's it.

Micha

--
http://mfesser.de/blickwinkel
Re: OOP versus Procedural/Functional [message #177584 is a reply to message #177576] Tue, 10 April 2012 15:07 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <jm17jg$iq0$1(at)news(dot)albasani(dot)net>,
The Natural Philosopher <tnp(at)invalid(dot)invalid> wrote:

> Goran wrote:
>> On 9.4.2012 21:35, Mr. B-o-B wrote:
>>> I was curious about peoples thoughts in regards to OOP with PHP.
>>>
>>> Are there pro's/con's of writing OOP code versus procedural/functional
>>> coding?
>>
>> If you stick with procedural programming you will never get a decent job :D
>
> True. Its one of those fashions that everybody has to do, like wearing a
> suit at a bank used to be.
>
> No doubt it will pass in time.

OO could be dangerous:

<http://www.danielsen.com/jokes/objecttoaster.txt>

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Re: OOP versus Procedural/Functional [message #177586 is a reply to message #177584] Tue, 10 April 2012 15:28 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Tim Streater wrote:
> In article <jm17jg$iq0$1(at)news(dot)albasani(dot)net>,
> The Natural Philosopher <tnp(at)invalid(dot)invalid> wrote:
>
>> Goran wrote:
>>> On 9.4.2012 21:35, Mr. B-o-B wrote:
>>>> I was curious about peoples thoughts in regards to OOP with PHP.
>>>>
>>>> Are there pro's/con's of writing OOP code versus procedural/functional
>>>> coding?
>>>> If you stick with procedural programming you will never get a
>> decent job :D
>>
>> True. Its one of those fashions that everybody has to do, like wearing
>> a suit at a bank used to be.
>>
>> No doubt it will pass in time.
>
> OO could be dangerous:
>
> <http://www.danielsen.com/jokes/objecttoaster.txt>
>

That was exactly the sort of scenario that downed my friends company.

Thanks for the laugh.



--
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.
Re: OOP versus Procedural/Functional [message #177587 is a reply to message #177556] Tue, 10 April 2012 15:29 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 09/04/2012 21:35, Mr. B-o-B escribió/wrote:
> I was curious about peoples thoughts in regards to OOP with PHP.
>
> Are there pro's/con's of writing OOP code versus procedural/functional
> coding?
>
> Strictly speaking for PHP, I do the bulk of my coding as
> procedural/functional. I really haven't found any added benefit to going
> the OOP route.
>
> Am I missing something, or is it just a different approach to the same
> problem?

IMHO, OOP suffers from two problems that aren't actually intrinsic to it:

1. For many people, it's a religion. This leads to endless debates about
design patterns and implementation subtleties that replace actual code
typing. It also leads to teachers and teaching materials that focus on
how utterly complex and philosophical OOP is rather than how useful it
is. (There seems to be a endless flow of OOP tutorials out there that
explain how to code cats and dogs and, apparently, it requires many
lines of code.)

2. Discussions about OOP always assume that there's only one type of
application to be written and only one type of team to write it: the
mega enterprisey ERP financed by a big-bucks customer maintained by a
20+ team.

To make it worse, most of the noise comes from fairly experienced
non-PHP programmers who are forced to code in a language they neither
understand nor like and get frustrated when they can't make PHP behave
like Java.

OOP is a tool. It's a darn good tool and it's just one more tool: that
says it all. I suffer when I see a thousand lines of getters and setters
that actually do nothing and I suffer when I see a shopping cart build
on top of 5-level nested arrays.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: OOP versus Procedural/Functional [message #177588 is a reply to message #177587] Tue, 10 April 2012 15:34 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Álvaro G. Vicario wrote:
> El 09/04/2012 21:35, Mr. B-o-B escribió/wrote:
>> I was curious about peoples thoughts in regards to OOP with PHP.
>>
>> Are there pro's/con's of writing OOP code versus procedural/functional
>> coding?
>>
>> Strictly speaking for PHP, I do the bulk of my coding as
>> procedural/functional. I really haven't found any added benefit to going
>> the OOP route.
>>
>> Am I missing something, or is it just a different approach to the same
>> problem?
>
> IMHO, OOP suffers from two problems that aren't actually intrinsic to it:
>
> 1. For many people, it's a religion. This leads to endless debates about
> design patterns and implementation subtleties that replace actual code
> typing. It also leads to teachers and teaching materials that focus on
> how utterly complex and philosophical OOP is rather than how useful it
> is. (There seems to be a endless flow of OOP tutorials out there that
> explain how to code cats and dogs and, apparently, it requires many
> lines of code.)
>
> 2. Discussions about OOP always assume that there's only one type of
> application to be written and only one type of team to write it: the
> mega enterprisey ERP financed by a big-bucks customer maintained by a
> 20+ team.
>
> To make it worse, most of the noise comes from fairly experienced
> non-PHP programmers who are forced to code in a language they neither
> understand nor like and get frustrated when they can't make PHP behave
> like Java.
>
> OOP is a tool. It's a darn good tool and it's just one more tool: that
> says it all. I suffer when I see a thousand lines of getters and setters
> that actually do nothing and I suffer when I see a shopping cart build
> on top of 5-level nested arrays.
>
Just try tracing any simple action like pressing a key in a modern OO
program.

It is horrendous. I like the OO paradigm - its a good tool and I learnt
from it. But I don't write for OO languages. I don't need to as I am not
coding for mega-enterprises.

Sometimes a state machine is a good tool too..just depends what you are
trying to do.


>


--
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.
Re: OOP versus Procedural/Functional [message #177590 is a reply to message #177584] Tue, 10 April 2012 16:08 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/10/2012 11:07 AM, Tim Streater wrote:
> In article <jm17jg$iq0$1(at)news(dot)albasani(dot)net>,
> The Natural Philosopher <tnp(at)invalid(dot)invalid> wrote:
>
>> Goran wrote:
>>> On 9.4.2012 21:35, Mr. B-o-B wrote:
>>>> I was curious about peoples thoughts in regards to OOP with PHP.
>>>>
>>>> Are there pro's/con's of writing OOP code versus procedural/functional
>>>> coding?
>>>> If you stick with procedural programming you will never get a
>> decent job :D
>>
>> True. Its one of those fashions that everybody has to do, like wearing
>> a suit at a bank used to be.
>>
>> No doubt it will pass in time.
>
> OO could be dangerous:
>
> <http://www.danielsen.com/jokes/objecttoaster.txt>
>

LOL, Beautiful, Tim!

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: OOP versus Procedural/Functional [message #177602 is a reply to message #177584] Tue, 10 April 2012 17:14 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 10.04.2012 17:07, schrieb Tim Streater:
> In article <jm17jg$iq0$1(at)news(dot)albasani(dot)net>,
> The Natural Philosopher <tnp(at)invalid(dot)invalid> wrote:
>
>> Goran wrote:
>>> On 9.4.2012 21:35, Mr. B-o-B wrote:
>>>> I was curious about peoples thoughts in regards to OOP with PHP.
>>>>
>>>> Are there pro's/con's of writing OOP code versus procedural/functional
>>>> coding?
>>>> If you stick with procedural programming you will never get a decent job :D
>>
>> True. Its one of those fashions that everybody has to do, like wearing a suit at a
>> bank used to be.
>>
>> No doubt it will pass in time.
>
> OO could be dangerous:
>
> <http://www.danielsen.com/jokes/objecttoaster.txt>
>

And Prolog is only good to find new aspects in your family - fathers, mothers,
uncles, children.

And Lisp is just the best choice to find the greatest common denominator.

no links about that, my experience. I guess the list of irrelevant programming
examples is ever growing, to infinity.

/Str.
Re: OOP versus Procedural/Functional [message #177603 is a reply to message #177602] Tue, 10 April 2012 17:19 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
M. Strobel wrote:
> Am 10.04.2012 17:07, schrieb Tim Streater:
>> In article <jm17jg$iq0$1(at)news(dot)albasani(dot)net>,
>> The Natural Philosopher <tnp(at)invalid(dot)invalid> wrote:
>>
>>> Goran wrote:
>>>> On 9.4.2012 21:35, Mr. B-o-B wrote:
>>>> > I was curious about peoples thoughts in regards to OOP with PHP.
>>>> >
>>>> > Are there pro's/con's of writing OOP code versus procedural/functional
>>>> > coding?
>>>> > If you stick with procedural programming you will never get a decent job :D
>>> True. Its one of those fashions that everybody has to do, like wearing a suit at a
>>> bank used to be.
>>>
>>> No doubt it will pass in time.
>> OO could be dangerous:
>>
>> <http://www.danielsen.com/jokes/objecttoaster.txt>
>>
>
> And Prolog is only good to find new aspects in your family - fathers, mothers,
> uncles, children.
>
> And Lisp is just the best choice to find the greatest common denominator.
>
> no links about that, my experience. I guess the list of irrelevant programming
> examples is ever growing, to infinity.
>

Loads of Irrelevant Superfluous Parentheses, isn't it?

If you can't code, talk about programming languages and if you can't
even do that, design a new one based on some Obscure Academic Principle.

> /Str.


--
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.
Re: OOP versus Procedural/Functional [message #177627 is a reply to message #177556] Wed, 11 April 2012 11:16 Go to previous messageGo to next message
crankypuss is currently offline  crankypuss
Messages: 147
Registered: March 2011
Karma: 0
Senior Member
On 04/09/2012 01:35 PM, Mr. B-o-B wrote:
> I was curious about peoples thoughts in regards to OOP with PHP.
>
> Are there pro's/con's of writing OOP code versus procedural/functional
> coding?
>
> Strictly speaking for PHP, I do the bulk of my coding as
> procedural/functional. I really haven't found any added benefit to going
> the OOP route.
>
> Am I missing something, or is it just a different approach to the same
> problem?

OOP is basically a good idea carried to an extreme.

There is a boatload of value in the concept of inheritance, but that's
largely negated by the mechanics of how inheritance is done in OOP
languages.

Polymorphism is something that's more in the eye of the programmer than
in the language, data constructs can be specific or generalized.

The idea that making something into an object gives it superior
robustness is a joke if you can step back and look at it.

I remember writing a Java application and trying to derive an actually
useful string class from the garbage they had declared "final" and that
was it for me and Java. I cannot begin to count the times when I've had
to hoke up an object pointer to use some simple processing method that
was part of a C++ class.

Of course that's all personal opinion. I avoid all OOP constructs in
PHP wherever I can, the more closely I can make it resemble C the easier
it will be to convert it when the time comes. There is one exception to
that in my code, one of the zip functionalities is only supported
through some objects... that stuff is encapsulated in a subroutine.

Since I value inheritance I've build myself a layered methodology that
lets me override various functions by adding or inserting different
layers at runtime.

Perhaps the nicest thing about programming is that it puts the lie to
religious adherences... as one of my college instructors put it, "if
your program works for all cases it is by definition correct".
Re: OOP versus Procedural/Functional [message #177628 is a reply to message #177627] Wed, 11 April 2012 14:25 Go to previous messageGo to next message
Goran is currently offline  Goran
Messages: 38
Registered: January 2011
Karma: 0
Member
On 11.4.2012 13:16, crankypuss wrote:
> I remember writing a Java application and trying to derive an actually
> useful string class from the garbage they had declared "final" and that
> was it for me and Java.

Just for curiosity, which method you tried to override? Somehow i smell
a good reason for "final" :)
Re: OOP versus Procedural/Functional [message #177629 is a reply to message #177628] Wed, 11 April 2012 17:06 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/11/2012 10:25 AM, Goran wrote:
> On 11.4.2012 13:16, crankypuss wrote:
>> I remember writing a Java application and trying to derive an actually
>> useful string class from the garbage they had declared "final" and that
>> was it for me and Java.
>
> Just for curiosity, which method you tried to override? Somehow i smell
> a good reason for "final" :)

Actually, I agree with Cranky on this one. I, too, have wanted to
override the java String class and been frustrated by its 'final'
attribute. I don't see why it couldn't have been created as non-final -
and it would have been a lot more usable.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: OOP versus Procedural/Functional [message #177630 is a reply to message #177627] Wed, 11 April 2012 17:09 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 11.04.2012 13:16, schrieb crankypuss:
> On 04/09/2012 01:35 PM, Mr. B-o-B wrote:
>> I was curious about peoples thoughts in regards to OOP with PHP.
>>
>> Are there pro's/con's of writing OOP code versus procedural/functional
>> coding?
>>
>> Strictly speaking for PHP, I do the bulk of my coding as
>> procedural/functional. I really haven't found any added benefit to going
>> the OOP route.
>>
>> Am I missing something, or is it just a different approach to the same
>> problem?
>
> OOP is basically a good idea carried to an extreme.
>
> There is a boatload of value in the concept of inheritance, but that's largely
> negated by the mechanics of how inheritance is done in OOP languages.
>
> Polymorphism is something that's more in the eye of the programmer than in the
> language, data constructs can be specific or generalized.
>
> The idea that making something into an object gives it superior robustness is a joke
> if you can step back and look at it.
>
> I remember writing a Java application and trying to derive an actually useful string
> class from the garbage they had declared "final" and that was it for me and Java. I
> cannot begin to count the times when I've had to hoke up an object pointer to use
> some simple processing method that was part of a C++ class.
>
> Of course that's all personal opinion. I avoid all OOP constructs in PHP wherever I
> can, the more closely I can make it resemble C the easier it will be to convert it
> when the time comes. There is one exception to that in my code, one of the zip
> functionalities is only supported through some objects... that stuff is encapsulated
> in a subroutine.
>
> Since I value inheritance I've build myself a layered methodology that lets me
> override various functions by adding or inserting different layers at runtime.
>
> Perhaps the nicest thing about programming is that it puts the lie to religious
> adherences... as one of my college instructors put it, "if your program works for all
> cases it is by definition correct".

Second phrase could have been "But there are many more aspects of software quality".

/Str.
Re: OOP versus Procedural/Functional [message #177631 is a reply to message #177629] Wed, 11 April 2012 17:18 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <jm4dnm$cj7$1(at)dont-email(dot)me>,
Jerry Stuckle <jstucklex(at)attglobal(dot)net> wrote:

> On 4/11/2012 10:25 AM, Goran wrote:
>> On 11.4.2012 13:16, crankypuss wrote:
>>> I remember writing a Java application and trying to derive an actually
>>> useful string class from the garbage they had declared "final" and that
>>> was it for me and Java.
>>
>> Just for curiosity, which method you tried to override? Somehow i smell
>> a good reason for "final" :)
>
> Actually, I agree with Cranky on this one. I, too, have wanted to
> override the java String class and been frustrated by its 'final'
> attribute. I don't see why it couldn't have been created as non-final -
> and it would have been a lot more usable.

Somehow this reminds me of one of the Pascal pig's ears: that two
strings of different lengths were different types.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Re: OOP versus Procedural/Functional [message #177634 is a reply to message #177631] Wed, 11 April 2012 20:24 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/11/2012 1:18 PM, Tim Streater wrote:
> In article <jm4dnm$cj7$1(at)dont-email(dot)me>,
> Jerry Stuckle <jstucklex(at)attglobal(dot)net> wrote:
>
>> On 4/11/2012 10:25 AM, Goran wrote:
>>> On 11.4.2012 13:16, crankypuss wrote:
>>>> I remember writing a Java application and trying to derive an actually
>>>> useful string class from the garbage they had declared "final" and
>> that
>>>> was it for me and Java.
>>>
>>> Just for curiosity, which method you tried to override? Somehow i smell
>>> a good reason for "final" :)
>>
>> Actually, I agree with Cranky on this one. I, too, have wanted to
>> override the java String class and been frustrated by its 'final'
>> attribute. I don't see why it couldn't have been created as non-final
>> - and it would have been a lot more usable.
>
> Somehow this reminds me of one of the Pascal pig's ears: that two
> strings of different lengths were different types.
>
LOL. Yes, Pascal takes strict typing (more than) a bit too far. And
for that very reason I think it's a good training language - but a
crappy development language.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: OOP versus Procedural/Functional [message #177639 is a reply to message #177634] Wed, 11 April 2012 21:43 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <jm4pao$lqh$1(at)dont-email(dot)me>,
Jerry Stuckle <jstucklex(at)attglobal(dot)net> wrote:

> On 4/11/2012 1:18 PM, Tim Streater wrote:
>> In article <jm4dnm$cj7$1(at)dont-email(dot)me>,
>> Jerry Stuckle <jstucklex(at)attglobal(dot)net> wrote:
>>
>>> On 4/11/2012 10:25 AM, Goran wrote:
>>>> On 11.4.2012 13:16, crankypuss wrote:
>>>> > I remember writing a Java application and trying to derive an actually
>>>> > useful string class from the garbage they had declared "final" and
>>> that
>>>> > was it for me and Java.
>>>>
>>>> Just for curiosity, which method you tried to override? Somehow i smell
>>>> a good reason for "final" :)
>>>
>>> Actually, I agree with Cranky on this one. I, too, have wanted to
>>> override the java String class and been frustrated by its 'final'
>>> attribute. I don't see why it couldn't have been created as non-final
>>> - and it would have been a lot more usable.
>>
>> Somehow this reminds me of one of the Pascal pig's ears: that two
>> strings of different lengths were different types.
>>
> LOL. Yes, Pascal takes strict typing (more than) a bit too far. And
> for that very reason I think it's a good training language - but a
> crappy development language.

Sure - as it was intended to be.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Re: OOP versus Procedural/Functional [message #177654 is a reply to message #177628] Thu, 12 April 2012 11:54 Go to previous messageGo to next message
crankypuss is currently offline  crankypuss
Messages: 147
Registered: March 2011
Karma: 0
Senior Member
On 04/11/2012 08:25 AM, Goran wrote:
> On 11.4.2012 13:16, crankypuss wrote:
>> I remember writing a Java application and trying to derive an actually
>> useful string class from the garbage they had declared "final" and that
>> was it for me and Java.
>
> Just for curiosity, which method you tried to override? Somehow i smell
> a good reason for "final" :)

That was sometime around 1998 and those bits have long ago scrolled off
the LRU list. <g>
Re: OOP versus Procedural/Functional [message #177655 is a reply to message #177630] Thu, 12 April 2012 11:56 Go to previous messageGo to next message
crankypuss is currently offline  crankypuss
Messages: 147
Registered: March 2011
Karma: 0
Senior Member
On 04/11/2012 11:09 AM, M. Strobel wrote:
> Am 11.04.2012 13:16, schrieb crankypuss:
>> On 04/09/2012 01:35 PM, Mr. B-o-B wrote:
>>> I was curious about peoples thoughts in regards to OOP with PHP.
>>>
>>> Are there pro's/con's of writing OOP code versus procedural/functional
>>> coding?
>>>
>>> Strictly speaking for PHP, I do the bulk of my coding as
>>> procedural/functional. I really haven't found any added benefit to going
>>> the OOP route.
>>>
>>> Am I missing something, or is it just a different approach to the same
>>> problem?
>>
>> OOP is basically a good idea carried to an extreme.
>>
>> There is a boatload of value in the concept of inheritance, but that's largely
>> negated by the mechanics of how inheritance is done in OOP languages.
>>
>> Polymorphism is something that's more in the eye of the programmer than in the
>> language, data constructs can be specific or generalized.
>>
>> The idea that making something into an object gives it superior robustness is a joke
>> if you can step back and look at it.
>>
>> I remember writing a Java application and trying to derive an actually useful string
>> class from the garbage they had declared "final" and that was it for me and Java. I
>> cannot begin to count the times when I've had to hoke up an object pointer to use
>> some simple processing method that was part of a C++ class.
>>
>> Of course that's all personal opinion. I avoid all OOP constructs in PHP wherever I
>> can, the more closely I can make it resemble C the easier it will be to convert it
>> when the time comes. There is one exception to that in my code, one of the zip
>> functionalities is only supported through some objects... that stuff is encapsulated
>> in a subroutine.
>>
>> Since I value inheritance I've build myself a layered methodology that lets me
>> override various functions by adding or inserting different layers at runtime.
>>
>> Perhaps the nicest thing about programming is that it puts the lie to religious
>> adherences... as one of my college instructors put it, "if your program works for all
>> cases it is by definition correct".
>
> Second phrase could have been "But there are many more aspects of software quality".
>
> /Str.

Sure, and if he'd really wanted his students prepared for the real world
he'd have said something about quality being meaningless in the face of
profit, so what?
Re: OOP versus Procedural/Functional [message #177663 is a reply to message #177655] Thu, 12 April 2012 15:33 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 12.04.2012 13:56, schrieb crankypuss:
> On 04/11/2012 11:09 AM, M. Strobel wrote:
>> Am 11.04.2012 13:16, schrieb crankypuss:
>>> On 04/09/2012 01:35 PM, Mr. B-o-B wrote:
>>>> I was curious about peoples thoughts in regards to OOP with PHP.
>>>>
>>>> Are there pro's/con's of writing OOP code versus procedural/functional
>>>> coding?
>>>>
>>>> Strictly speaking for PHP, I do the bulk of my coding as
>>>> procedural/functional. I really haven't found any added benefit to going
>>>> the OOP route.
>>>>
>>>> Am I missing something, or is it just a different approach to the same
>>>> problem?
>>>
>>> OOP is basically a good idea carried to an extreme.
>>>
>>> There is a boatload of value in the concept of inheritance, but that's largely
>>> negated by the mechanics of how inheritance is done in OOP languages.
>>>
>>> Polymorphism is something that's more in the eye of the programmer than in the
>>> language, data constructs can be specific or generalized.
>>>
>>> The idea that making something into an object gives it superior robustness is a joke
>>> if you can step back and look at it.
>>>
>>> I remember writing a Java application and trying to derive an actually useful string
>>> class from the garbage they had declared "final" and that was it for me and Java. I
>>> cannot begin to count the times when I've had to hoke up an object pointer to use
>>> some simple processing method that was part of a C++ class.
>>>
>>> Of course that's all personal opinion. I avoid all OOP constructs in PHP wherever I
>>> can, the more closely I can make it resemble C the easier it will be to convert it
>>> when the time comes. There is one exception to that in my code, one of the zip
>>> functionalities is only supported through some objects... that stuff is encapsulated
>>> in a subroutine.
>>>
>>> Since I value inheritance I've build myself a layered methodology that lets me
>>> override various functions by adding or inserting different layers at runtime.
>>>
>>> Perhaps the nicest thing about programming is that it puts the lie to religious
>>> adherences... as one of my college instructors put it, "if your program works for all
>>> cases it is by definition correct".
>>
>> Second phrase could have been "But there are many more aspects of software quality".
>>
>> /Str.
>
> Sure, and if he'd really wanted his students prepared for the real world he'd have
> said something about quality being meaningless in the face of profit, so what?

Ignoring good advice, "state of the art", "best practices" isn't something to teach.
It happens.

And quality is not completely meaningless if the customer can have a look at the code
and see what he is paying for.

/Str.
Re: OOP versus Procedural/Functional [message #177668 is a reply to message #177663] Thu, 12 April 2012 17:18 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/12/2012 11:33 AM, M. Strobel wrote:
> Am 12.04.2012 13:56, schrieb crankypuss:
>> On 04/11/2012 11:09 AM, M. Strobel wrote:
>>> Am 11.04.2012 13:16, schrieb crankypuss:
>>>> On 04/09/2012 01:35 PM, Mr. B-o-B wrote:
>>>> > I was curious about peoples thoughts in regards to OOP with PHP.
>>>> >
>>>> > Are there pro's/con's of writing OOP code versus procedural/functional
>>>> > coding?
>>>> >
>>>> > Strictly speaking for PHP, I do the bulk of my coding as
>>>> > procedural/functional. I really haven't found any added benefit to going
>>>> > the OOP route.
>>>> >
>>>> > Am I missing something, or is it just a different approach to the same
>>>> > problem?
>>>>
>>>> OOP is basically a good idea carried to an extreme.
>>>>
>>>> There is a boatload of value in the concept of inheritance, but that's largely
>>>> negated by the mechanics of how inheritance is done in OOP languages.
>>>>
>>>> Polymorphism is something that's more in the eye of the programmer than in the
>>>> language, data constructs can be specific or generalized.
>>>>
>>>> The idea that making something into an object gives it superior robustness is a joke
>>>> if you can step back and look at it.
>>>>
>>>> I remember writing a Java application and trying to derive an actually useful string
>>>> class from the garbage they had declared "final" and that was it for me and Java. I
>>>> cannot begin to count the times when I've had to hoke up an object pointer to use
>>>> some simple processing method that was part of a C++ class.
>>>>
>>>> Of course that's all personal opinion. I avoid all OOP constructs in PHP wherever I
>>>> can, the more closely I can make it resemble C the easier it will be to convert it
>>>> when the time comes. There is one exception to that in my code, one of the zip
>>>> functionalities is only supported through some objects... that stuff is encapsulated
>>>> in a subroutine.
>>>>
>>>> Since I value inheritance I've build myself a layered methodology that lets me
>>>> override various functions by adding or inserting different layers at runtime.
>>>>
>>>> Perhaps the nicest thing about programming is that it puts the lie to religious
>>>> adherences... as one of my college instructors put it, "if your program works for all
>>>> cases it is by definition correct".
>>>
>>> Second phrase could have been "But there are many more aspects of software quality".
>>>
>>> /Str.
>>
>> Sure, and if he'd really wanted his students prepared for the real world he'd have
>> said something about quality being meaningless in the face of profit, so what?
>
> Ignoring good advice, "state of the art", "best practices" isn't something to teach.
> It happens.
>
> And quality is not completely meaningless if the customer can have a look at the code
> and see what he is paying for.
>
> /Str.

They ARE things which should be included in every course. We do it in
ours - which is one reason corporations like us.

Corporations are interested in quality. Support costs are a major expense.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Does PHP5 treat $_SERVER['PHP_AUTH_USER']) differently?
Next Topic: Clean PDO-MySQL Statement
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 08:49:57 GMT 2024

Total time taken to generate the page: 0.02955 seconds