Page 5 of 6

Posted: Thu Mar 10, 2005 10:29 am
by Roja
feyd wrote:If maintainability, upgradability, and/or flexibility is more critical, then OOP is a good direction to head. At the very least, seperation of presentation from logic is often critical at that level.
Just to clarify, I do agree that there is value to OOP, that there are places and times when it *is* superior to procedural, and that programmers should learn it.

I just disagree that there OOP is always better, that OOP is the only way, and that any one who thinks otherwise is unintelligent or inexperienced.

I'm pragmatic on it, although I do feel there are places where OOP is idiotic and not helpful. Hello world comes to mind. :)

Posted: Thu Mar 10, 2005 10:47 am
by McGruff
I'm not setting out to attack anyone but, as I said, someone has to stand up for basic intellectual standards. If you find yourself on the wrong side of that it's no shame. It's an opportunity to learn something.

The speed issue for example is humbug. That's one of the signs of lack of experience I'm talking about. OOP can easily work out faster not least because a well-designed app is much more amenable to optimisation.

In the link you gave it was said Rasmus viewed php as a templating system. If that were true, he's getting a bit out of touch with his own language (or was it just an old article?). Php is capable of much more than that.

Posted: Thu Mar 10, 2005 10:50 am
by patrikG
Roja was making the point that OOP makes sense above a certain threshold of complexity.

Posted: Thu Mar 10, 2005 10:59 am
by McGruff
Yes there were several points raised in the last two posts.

However, the complexity argument is another red herring. It would be wrong to restrict OOP to just "complex" problems. The benefits kick in very early on after "hello world".

Posted: Thu Mar 10, 2005 11:20 am
by BDKR
McGruff wrote:Please note that I've already warned one member who shall remain nameless about personal comments in a now deleted post. Say what you like but stick to programming.
I think this is as good a jumping off place as any. Here is what you responded back to me earlier in this thread.
McGruff wrote: I do think it's important to make the point that, almost without exception, the whole thing just sounds naive to more experienced programmers. In fact, you're the only one I know who doesn't seem to think so. Where people stand on the OOP "debate" is almost a litmus test of their programming knowledge.
In other words, becuase I refuse to take your staunch view on the topic my knowledge is suspect? Let's look at that first.

I presently am the lead developer for a site that did over a million dollars net revenue in it's first full year of business. The site was a big
bowl of sphaghetti as far as the code was concerned. The classes suX0r too! There wasn't even any error reporting. I've since cleaned up large
portions of the code, created a template to speed the development of new adminstrative features in the back end, and introduced my own
OO framework.

I'm also completing the extension of the original sites backend to act as a common processing system for multipler web sites and
affiliates.

And that's just code. I also built a cluster of machines to handle the increasing traffic with Two Cisco Localdirectors at the heart
of the system. This also required code to monitor the health of the redundant databases servers, manage and report those errors, hold
elections amongst slave servers, and promotion of the elected server to the master. I used a mixture of procedural and OO here. It only
made sense to realize the individual databases and the fail boss as objects.

For a company in Fort Myers, I laid the foundation for a system that would report the status of orders and CAM stations on a production
floor using Python. We all know that Python is basically an OOL and not a hybrid like PHP, Perl, or Objective C.

In Venezuela I built and managed a cluster where I wrote a different implementation (that was not anywhere near as smooth as the present) of database
failover code. For this same company I created tons of adminstrative utilities (not to mention a complete deposit and withdrawal system),
what I like to call battlefield code (small hacks that were immensely useful during an emergency), as well as code to monitor, manage and
control a WWAN (Wireless Wide Area Network). I even stamped out a prototype of an SQL load balancer in PHP!

Most of the database access code written while I was there was OO in design only as the nature of the business my company was in meant this
portion of the code was critical and needed to perform at the highest possible level. When most of our transactions occurred in the last
5 minutes before post time (Lottery and Horse Racing), that meant the load on the database rose dramatically and stayed high for a short period
after the race was complete. In our minds, that meant the roughly 30% overhead from ADODB/DBX, 50% from
MDB, 160% from Pear, and 260% from Metabase
(all numbers being approximate. Follow the link for more exact numbers) just simply wasn't acceptable.

And the list goes on, but I think that should suffice.

What's really interesting is that nobody said OOP is bad. OOP sucks. All we say is that it's not good for everything. If it were the case that
OOP is good for everything and the only possible route to success then MySQL, Postgres, Linux, Windows, Solaris, Apache, PHP, Python, the Half Life 2 engine, the Quake engines, fuel injection control code, and even drivers would be written using actual objects.

BUT THEY AREN'T!

Additionaly, some of the people behind the projects and products mentioned above are very notable indeed. Rasmus, Sterling, Ilia, Zeev and the rest are very knowledgeable. As a matter of fact, it was Sterling and Thies that were responsible for an
update (that for one reason or another didn't make it into production) that improved
performance over 100%! John Carmack is considered the cutting edge in real time 3D engine (game engine) development. Linus Toorvalds
and Alan Cox are absolute gods when it comes to Kernel development.

And many of the above are not proponents of 100% usage of OOP!

There is also a fair share of warning out there about issues relating to
the use of large OO frameworks. John Lim and Joel Spolksy are but a few who've chimed in here.

However, if we use the metrics you've thus far set forth, then the knowledge of the above mentioned individuals is questionable and
naive.

Lastly, the person that helped me understand OO and shaped many of my views on the subject is named Timothy Budd.
A professor at Oregon State University. Here is a quote from his book (one of the many) "An Introduction to Object-Oriented Programming".
Timothy Budd wrote: Working in an object-oriented language (that is, one that supprots inheritance, message passing, and classes) is neither a necessary nor sufficient condition for doing object-oriented programming. As we emphasized in Chapter 1, the most important aspect of OOP is a design techinque driven by the determination of deleagion of responsibilities. This technique has been called responsibility driven design [Wirfs-Brock 1989b, Wirfs-Brock 1990].
So are you saying that Mr Budd, a professor, who instructs courses and has written books on the topic should henceforth be considered with suspicion? Wouldn't the board of directors at his University and his peers have him removed if this was indeed true?

Ultimately, the opinion from a LARGE number of individuals with more noteriety than you is against you. But of course, if you feel
that we are all wrong then it's up to you to prove it. And please refrain from personal comments like...
McGruff wrote: I do think it's important to make the point that, almost without exception, the whole thing just sounds naive to more experienced programmers.
In fact, you're the only one I know who doesn't seem to think so.
Relax a bit! Nobody is against you here. We just don't agree.

Posted: Thu Mar 10, 2005 11:41 am
by Buddha443556
McGruff wrote:OK. Forget what Rasmus has or hasn't said. Of course you have a choice in the sense that you can travel to work by bicycle or you can learn to drive and use a car. Do we agree that OOP is more powerful?
No we don't agree OOP is more powerful. I believe the power lies in the programmer not the technology. Is a programmer more powerful with OOP knowledge? Yes. The more knowledge the better. The more experience the better.
McGruff wrote:Some of the PoEEA patterns might be do-able procedurally but many simply don't make sense (Object-Relational mapping..). Some you might find rather difficult without encapsulation eg Gateways and ServiceLayers.
I'll simply agree an OOPL makes some things easier. I might even go so far as to say many things easier.
McGruff wrote:I have to ask, have you read the book?
Yes, in reach with pages falling out too.
McGruff wrote:I brought up PoEEA in the first place because OOP is much more than just knowing the syntax to define a class. It's about making the effort to truly understand what's going on in your scripts, separating the different threads into discrete units of functionality all the way down from the presentation/domain/data layering to the myriad groups of co-operating objects within each layer. It all gets quite pattern heavy and it's exactly this kind of conceptual richness that makes OOP so powerful. PoEEA is one of the classic texts on the subject.
I'm for 'truly understanding what's going on in your scripts.' However, I feel it's also important to understand what's going on in the underlying technology too.
feyd wrote:In a compiled language, I would more agree with McGruff that OOP is about the only way things should be done..

However, PHP is not a compiled language. So when the interpreter has to run over lots of OOP stuff, it does add more time. If speed is critical, procedural code will often be faster. Not necessarily by much, but every little bit helps. If maintainability, upgradability, and/or flexibility is more critical, then OOP is a good direction to head. At the very least, seperation of presentation from logic is often critical at that level.
It takes experience to see the big picture. How your script fits into the supporting technology. Something simply knowledge won't give you.
McGruff wrote:There's no disgrace in not being familiar with advanced OOP theory. You'll find a lot of people will be glad to share their knowledge and enthusiasm if you're willing to learn. But, out of respect for basic intellectual standards and for learner programmers who might be misled, I'm taking no prisoners.
That's why we are all here to help and to learn. It might help though if you don't view those disagreeing with you as the enemies to be slaughtered. Some could take offense.
Indeed, I believe that the primary benefit of objects is in making complex logic tractable.
Sort of the point of all methodologies isn't it?

Posted: Thu Mar 10, 2005 12:45 pm
by McGruff
BDKR wrote:In other words, becuase I refuse to take your staunch view on the topic my knowledge is suspect?
I thought I'd made it clear that I wasn't lumping you in with that group. I know you have a fair bit of experience.

If you're going to widen the terms of the debate to include the programming of drivers etc I'd agree that OOP isn't an automatic choice. However, assuming we're talking about php and the common kinds of web apps written in php, OOP is a more powerful and expressive solution.

I'm not sure if the point which you keep raising about OOD is relevant. Again, if we're talking specifically about php, the language does support classes and inheritance. Wouldn't it be kind of perverse to attempt OO design without using them?

So.. tests show that adobe is 30% slower. Did you test that on your own system? Optimisation isn't a simple subject as I'm sure you'll know.

Posted: Thu Mar 10, 2005 1:51 pm
by McGruff
Buddha443556 wrote:Yes, in reach with pages falling out too.
I humbly apologise :)

Posted: Thu Mar 10, 2005 2:03 pm
by BDKR
McGruff wrote: If you're going to widen the terms of the debate...
I'm not widening it at all. Here is what you've said so far in this discussion.
McGruff wrote: Everything should be an object...
and
McGruff wrote: With respect to previous posters, it's not a matter of personal preference. There is simply no comparison between OOP and procedural. You cannot approach anything like the power of OOP with other methods.
It sounds to me and others like you've increased the scope as far as it can go.
McGruff wrote: However, assuming we're talking about php and the common kinds of web apps written in php, OOP is a more powerful and expressive solution.
OOP is merely a facilitator to more elegant and reusable expressions of design.
McGruff wrote: Again, if we're talking specifically about php, the language does support classes and inheritance. Wouldn't it be kind of perverse to attempt OO design without using them?
Yes and no. What about when you have a valid reason for needing the speed but refuse to have messy code?

Anyway people have been doing it (using OOD) for some time. Windows is an example of such thinking. It can be argued that structs and modules are just evolutionary steps on the way to objects.

So, if I want to call this

Code: Select all

class queryObject
    {
    var $dbConnObject;        /* This is a reference to connection object */
    var $errorObject;            /* This is a reference to an error object */
    var $query;
    var $numRows;        
    }
    
/* OR */

$queryObject=array
    (
    'dbConnObject' => 'some connection object', 
    'errorObject' => 'some error object',
    'query' => 'the query string',
    'numRows' => 'the number of rows'    
    );

...an object or a struct, why not? (Notice that the class example has no methods!) At least I've bypassed the overhead of method lookup. The only thing that's left now is the overhead of instantiation.

So if I associate certain functions with either of the constructs above, it's still not an object proper, but it can be looked at in the design as such.

It will definitely look different too.

Code: Select all

executeQuery($queryObj);
as opposed to

Code: Select all

$queryObj->executeQuery();
While they look different, they are both doing the same thing no?

I can also do message passing and even generate new objects using a factory function.

But do I suggest that people do this most of the time? No. It's just not warranted. For us it was as we decided we didn't want to deal with the additional development time associated with a strongly typed language.

That said, it worked and worked well and was fast too.

I will say that I think it's good for someone to go through such an excercise at least once while learning. The reason being that it's very possible one could end up in a job, with a task, or a contract where something is required of them without the use of an OOL.
McGruff wrote: So.. tests show that adobe is 30% slower. Did you test that on your own system? Optimisation isn't a simple subject as I'm sure you'll know.
Well first off, so nobody is confused, that's ADODB, not adobe.

These tests were done by John Lim (the author of ADODB). There is a link in my last post.

Where optimization is concerned, that's not what we did in this case. Optimization normally occurs ex post facto (after the fact). For us, these
were design considerations and decisions made in advance of actual
coding. If while I'm writing a for loop I decide to pre-increment (++$i) as opposed to post-increment ($i++) becuase it's faster, that's an upfront
consideration. Not an after the fact optimization.

Posted: Thu Mar 10, 2005 2:27 pm
by Roja
BDKR wrote:
McGruff wrote: With respect to previous posters, it's not a matter of personal preference. There is simply no comparison between OOP and procedural. You cannot approach anything like the power of OOP with other methods.
It sounds to me and others like you've increased the scope as far as it can go.
This is the second iteration of the original jihad: viewtopic.php?t=27682

In the original, it got so bad, that I left the thread, after being warned for my comments. In this iteration, he has deleted a post of mine that he feels contained name-calling. Perhaps I get too personally insulted when grouped in with "Unintelligent" and "inexperienced" based on my point of view.

I will admit that I dont always choose the most friendly way to make that statement.

I agree with you, BDKR. He has made it clear that he will "Take no prisoners", and that his position is the only acceptable position. It makes it hard to disagree with him - even if I feel just as strongly as he does about his position.

However, with a moderator making that statement, and taking the actions he has, there is no point in me continuing. So, like last time, I will leave this thread. Much like last time, I feel there are at least competent people who are making the same argument I am, who will continue without being threatened with banning.

I stand by you BDKR, even if I do leave this thread.

However, in closing, I will point to the site rules, which states:

"Respect positions which differ from your own"

Posted: Thu Mar 10, 2005 2:50 pm
by McGruff
I've repeatedly made it clear that anyone can say what they like as long as they stick to programming. Some people don't want to talk about programming - your choice.

Posted: Thu Mar 10, 2005 5:32 pm
by Buddha443556
McGruff wrote:
Buddha443556 wrote:Yes, in reach with pages falling out too.
I humbly apologise :)
No need to apologise. Believe it or not, I do respect you even though I don't seem to ever agree with you.

Posted: Thu Mar 10, 2005 9:05 pm
by ast3r3x
This seems like a fun thread to ask a stupid question :D

I don't completely understand OOP. Maybe you can explain this a little better.

An object is just...well an object that can be acted upon easily by functions in a class right?

I never understood why you'd want to limit functions to one thing. I guess I use procedural programming, but I use lots of functions so I don't have to repeat code to get a task done.

McGruff, can you give me an example of how you'd use OO in creating that forum your talking about? I don't get how that would be too useful, listing a page you just use a loop and grab and output data.

The only thing I really see is making a user class/object, but you are only acting upon that user in certain cases. You have a script/page to login, that code is specific, you have a page/script to view that users information, that is specific.

I just don't get OO I guess, I have never seen a benefit over just using functions to reduce repeated code.

Anyone can answer those questions, I was just asking McGruff about his forum because I'm going to redo my forum from scratch, and if OO is amazingly better, I'd be stupid not to use it.

Posted: Fri Mar 11, 2005 7:14 pm
by McGruff
Sorry been busy making furniture today but I will get back to this. After making so many bold statements I know I now have to back them up.

Posted: Fri Mar 11, 2005 9:42 pm
by Ambush Commander
You know, I'm probably not the best person to say this because I've never used OOP before, but I've got this little idea. You can use arrays to collect data, but an object class is an actual "blueprint" for a class. This leads to a lot of cool things that helps coding immensely.

For instance, I have a fiction publishing site. As of now, I store all my information in three arrays: $sinf (story information) $sc (chapter inormation) and $authinf (author information).

But what would have made much more sense:

Code: Select all

AUTHOR CLASS {
 public $full_name;
 //...
 public $stories; //this is an array
}

//Then the array points to STORY objects
STORY CLASS {
 public $storyname;
 public $lastupdate;
 //...
}
Then, add constructor functions for pulling information out of a database and adding it to a class, and then think about functions that you'd only want to apply to information in a story, or maybe inside an author class, and your code becomes a lot cleaner. Why do you need a function that traverses an entire story counting words when you're outside of this story object?

Plus, you can use classes to organize functions (I know Invision Power Board does this).