Topic: What are the general uses of OOP?

I can only think of OOP being used as an SQL parser/interface or an error handler. But if I want an SQL interface, I can just use PDO. So what do/would you use OOP for?

By the way, why doesn't PunBB use PDO?

Re: What are the general uses of OOP?

???
that's weird, all the database layers around are OOP. i think you are mixing up the names.
If by OOP you mean Objected Oriented Programming

http://en.wikipedia.org/wiki/Object-ori … rogramming

BTW, i would also know more about punbb detabase layer. Was it developed for punbb specially? why? why not using an existent one?

Re: What are the general uses of OOP?

There are many pros and cons to object oriented programming. I won't go into any detail here though. Google it and you'll find a billion articles on the subject.

The reason PunBB does not use PDO is mainly because there are virtually zero hosting environments out there that have it enabled. PDO might be interesting in a year or two.

Edit: PunBB's db abstraction classes were loosely based on code from phpBB. Most of it is custom now though. The reason I did not go with any existing abstraction class is that there were no good ones when I started working on PunBB in 2002.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: What are the general uses of OOP?

OOP adds reliability to a program and it's more accurate

Re: What are the general uses of OOP?

thechamp54 wrote:

OOP adds reliability to a program and it's more accurate

I don't think I've ever heard that argument before: how is OOP inherently more reliable and accurate?

Re: What are the general uses of OOP?

OOP adds reliability to a program and it's more accurate

OOP is to programing what color is to tv.
color doesn't do anything for the message of a tv show. It makes it look all ... colorful ... though tongue
OOP doesn't improve a programmers code ... it makes it ... OOPful ... though tongue

By the way, why doesn't PunBB use PDO?

It does if you need sqlite3 support like I did, follow the link in the sig smile

echo "deadram"; echo; fortune;

Re: What are the general uses of OOP?

Smartys wrote:
thechamp54 wrote:

OOP adds reliability to a program and it's more accurate

I don't think I've ever heard that argument before: how is OOP inherently more reliable and accurate?

inheritance enforces a common functionality.  encapsulation ensures that I never step on common variables that lead to hard to find, and hard to fix once found problems.  strict object oriented programming removes global functions and variables that typically forces the developer to place that functionality in some common object.

being able to segment code into namespaces / packages / libraries further encapsulates objects and their members.  inheriting leaves less room for error as children typically inherit parent classes functionality, which means you write an object (like a base business object) that contains core level functionality (like database persistence) and all 900 of your implementing objects contain the same functionality.  if you correct a bug in the base class, all 900 benefit from it. 

lastly, it saves time by being able to reuse specific application logic while hiding or overriding other functionality.

I hated OOP when I first started learning it, but now could not do without it.

Re: What are the general uses of OOP?

All of which are positive aspects of OOP, but none of which make it inherently more "accurate" or "reliable": it's up to the programmer to take advantage of what OOP has to offer when it's needed, using OOP isn't a panacea

Re: What are the general uses of OOP?

imagine you're the author of an operating system.  you give an sdk for others to develop on.  lets say you hold your file allocation table in a globally accessible variable named foo.  now I, an idiot programmer, create a hello world application, and declare the value of some variable named foo, to a null pointer.  oops...  yes, I'd have to argue that being able to enforce that no one will ever assign

$pun_config = null;

somewhere after its loaded from the cache and before anyone needs to use it, is a more reliable method. 

anytime you can guarantee that some core level code of an application cannot be modified outside of the means you prescribe, is (at least to me) a better, more reliable means.

Re: What are the general uses of OOP?

MadHatter wrote:

imagine you're the author of an operating system.  you give an sdk for others to develop on.  lets say you hold your file allocation table in a globally accessible variable named foo.  now I, an idiot programmer, create a hello world application, and declare the value of some variable named foo, to a null pointer.  oops...  yes, I'd have to argue that being able to enforce that no one will ever assign

$pun_config = null;

somewhere after its loaded from the cache and before anyone needs to use it, is a more reliable method. 

anytime you can guarantee that some core level code of an application cannot be modified outside of the means you prescribe, is (at least to me) a better, more reliable means.

Foobar foo = new Foobar();
foo = null;

You can screw things up with or without OOP, you just screw them up in slightly different ways wink

Re: What are the general uses of OOP?

but thats something completely different. 

only reason I say this is because most of my career I've been a platform developer.  producing an sdk which allows some random developer to bring your system crashing down is never a good thing.  A strict API for accessing the system is far safer than providing some global access to data that the "black box" uses. Its not always avoidable (esp when we're talking about kernel level driver interaction), but there is a reason why operating systems are written using OOP. 

In general (especially with crappy implementations which abound) I think web development is best suited in a quasi-oop manner, and there is a happy medium between component, and OOP in web development especially when you have a versatile language like PHP to work with.  outside of the web however, I think its far more reliable in a strict OO manner.

Re: What are the general uses of OOP?

OOP is a syntax, not a way to control variable scope. Anything done in C++ can be done in C, using static variables, or "local" globals, or externs, etc... ie:

include.h ---

extern int x, y;

include.c ---

int x, y, z;

// do stuff to x, y, and/or z

main.h ---

#include include.h

// do stuff to only x or y... you know nothing about z at all... almost like z was a member variable of object include.h? wow...

int z = 5;

// Now in main.c z=5... it doesn't affect the variable z referenced in include.c

good structured programing would be to never declare variables as externs, and force any user of the include.h function set to pass pointers to an internal structure... wait? isn't this what an object is? a structure? with a series of functions, that when called automatically pass the pointer to the structure as the first/last param (depending on compiler, language, etc...). OOP is syntax, not functionality. You can have inherence without OOP, you can correct a single line in a function and fix a bug in 900 other functions that make use of it. Saying OOP is anything other then a style and a little extra overhead during compile time (but not always during runtime) is like saying a Toyota car can turn corners, so you shouldn't turn a corner in a Ford car, cause only Toyota's can turn corners... tongue You may turn the corner differently in a Ford, but simply because a Toyota can do it, doesn't mean a Ford can no longer tongue It's a style, and a person may be more adept at one or the other, but either one can and will get you from A to B just as fast, and efficiently (Ok... Ford was a bad example... A ford will get you from A to B with a $2,000 repair bill tongue But you get the idea smile ).

echo "deadram"; echo; fortune;

Re: What are the general uses of OOP?

oop is a concept (which btw is not strictly enforced by C++ because of its interoperability with C) enforced by a complier or interpreter. 

to that end, the concepts produced by such a thought, when implemented in a language, provide more reliability of data integrity than languages that allow global access of data.

lets say for a second that punbb was an oo implementation.  data access, configuration, and functionality were totally internal / private.  lets say that it had an extension framework that consisted of a base "extension" object from which one could inherit and do whatever with.  by using this type of model, one could never access the actual pun_config or db objects and the maintainer of this board could ensure that no extension / plugin could ever take a board down because mods never have access to internal core code, variables, or functionality. 

in my opinion, procedural programming concepts just don't provide the necessary functionality to produce reusable, extensible and data protected applications.  scripting is another thing, that I'm leaving out of this, but just on a conceptual level, I sticking by what I've said.

14 (edited by deadram 2007-03-01 06:31)

Re: What are the general uses of OOP?

MadHatter wrote:

in my opinion, procedural programming concepts just don't provide the necessary functionality to produce reusable, extensible and data protected applications.

I agree that conceptually OOP is better. In practice, OOP is better. I disagree that data, configuration, functionality, etc... couldn't be "private" in procedural programing though.

lets say for a second that punbb was an oo implementation.  ...snip

having an object to inherit, or having a series of functions that an extention has to call/have are the same thing. The object can require functions explicitly, the object can call functions implicitly. That's what OOP does. It adds a series of syntactical phrases that when parsed, explain to the compiler what the requirements to make use of a "block" of functions is, and what the requirements to extend a block of functions is. Procedural programming leaves all the infering to the coder, giving them more power and less parenting. But, if you are really freaky... Like I said before, find 1 thing you can do in OOP, that you couldn't do in procedural tongue

config.php...

function getDbName() { return "value"; }

// or... I dono...

function GetPunConfig($key)
{
  function __LoadVariables()
  {
     // Well... get the pun_config array from where ever... and return it :P
  }
  static $pun_config = __LoadVariables();

  switch ($key)
  {
    case 'joe_obsolete_variable':
      return 0;
      break;

    default:
      return $pun_config[$key];
      break;
  }
}

getDbName() { return GetVariable('db_name'); }

Now assign random values to $pun_config till you go blue in the fingers, and unless you've managed to get your cursor to the GetPunConfig function that config data is safer then a ~private~ member variable in an object! Ohhh, ohhh and try to call __LoadVariables();, I dare yah smile

echo "deadram"; echo; fortune;