PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Sep 20, 2020 12:02 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: OOP and Reusability
PostPosted: Wed Jun 13, 2012 6:47 pm 
Offline
Forum Regular
User avatar

Joined: Mon Feb 11, 2008 5:22 am
Posts: 613
I was reading an interesting interview with the creator of Erlang and something that was suggested was that OOP can lead to code being less rather than more re-usable, by virtue of the creation of highly specific "black boxes" which people are reluctant to tamper with.

By way of comparison with procedural programming for example, would anyone agree with this/have further thoughts?


Top
 Profile  
 
 Post subject: Re: OOP and Reusability
PostPosted: Wed Jun 13, 2012 9:07 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
...and then there's WordPress, which proves that if someone wants to write unmaintainable and poorly-designed code then they will.


Top
 Profile  
 
 Post subject: Re: OOP and Reusability
PostPosted: Wed Jun 13, 2012 9:41 pm 
Offline
Forum Regular
User avatar

Joined: Mon Feb 11, 2008 5:22 am
Posts: 613
I'm sorry but I'm not quite sure what your point is, nor am I sure quite in what way WordPress is "unmaintainable", given that it is an actively maintained project.


Top
 Profile  
 
 Post subject: Re: OOP and Reusability
PostPosted: Wed Jun 13, 2012 9:53 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
OOP or not, someone will either write good code or write bad code. Applies to coding in different languages too.

As for black boxes, it sounds to me like that someone doesn't quite realize how classes can be converted to and from sets of functions. Easily.
Syntax: [ Download ] [ Hide ]
class User {

        public $id;
        public $username;

        public function __construct() { }

        public function login() { ... }

        public function logout() { ... }

}

Syntax: [ Download ] [ Hide ]
function user_construct() {
        $data = array();
        $data["id"] = 0;
        $data["username"] = "";
        return $data;
}

function user_login($data) { ... }

function user_logout($data) { ... }

Now tell me, given $data in user_login(), what "variables" (array items) are available? Which ones can you safely modify? Which functions can you call from external code?


Top
 Profile  
 
 Post subject: Re: OOP and Reusability
PostPosted: Thu Jun 14, 2012 8:21 am 
Offline
Forum Regular
User avatar

Joined: Mon Feb 11, 2008 5:22 am
Posts: 613


Top
 Profile  
 
 Post subject: Re: OOP and Reusability
PostPosted: Thu Jun 14, 2012 2:37 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
You might want to look into . Siimply using classes does not guarantee well designed code.

_________________
(#10850)


Top
 Profile  
 
 Post subject: Re: OOP and Reusability
PostPosted: Thu Jun 14, 2012 10:18 pm 
Offline
Forum Regular
User avatar

Joined: Mon Feb 11, 2008 5:22 am
Posts: 613
Yeah I've read a couple of his (Bob's) books, which I suppose are tackling this same issue from the other angle - making sure components are clean and reusable before they are written. What interests me here is working with existing code and stems from some amount of despair about how un-reusable many chunks of code are; really I was interested in discussing the human dimension of this and if OOP somehow engenders unnecessary complexity in the code of many programmers.


Top
 Profile  
 
 Post subject: Re: OOP and Reusability
PostPosted: Thu Jun 14, 2012 11:14 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
 Post subject: Re: OOP and Reusability
PostPosted: Fri Jun 15, 2012 12:11 am 
Offline
Site Administrator
User avatar

Joined: Sun May 19, 2002 10:24 pm
Posts: 6887
I don't think the argument is or should be Procedural VS OOP. I think the issue is making best use of decomposition.

_________________
Image


Top
 Profile  
 
 Post subject: Re: OOP and Reusability
PostPosted: Fri Jun 15, 2012 12:34 am 
Offline
Forum Regular
User avatar

Joined: Mon Feb 11, 2008 5:22 am
Posts: 613


Top
 Profile  
 
 Post subject: Re: OOP and Reusability
PostPosted: Fri Jun 15, 2012 4:45 am 
Offline
Site Administrator
User avatar

Joined: Sun May 19, 2002 10:24 pm
Posts: 6887

_________________
Image


Top
 Profile  
 
 Post subject: Re: OOP and Reusability
PostPosted: Fri Jun 15, 2012 8:32 am 
Offline
Forum Regular
User avatar

Joined: Mon Feb 11, 2008 5:22 am
Posts: 613


Top
 Profile  
 
 Post subject: Re: OOP and Reusability
PostPosted: Tue Jul 03, 2012 7:51 pm 
Offline
DevNet Master
User avatar

Joined: Mon Sep 19, 2005 6:24 am
Posts: 3587
Location: London
In my experience of working with "legacy" code on what is now an alarming number of projects*, it is the temptation to "just add it here", or to "just change this bit here" that creates these black boxes. By that, I mean behaviour encapsulation, and behaviour separation are often overlooked in favour of speed of development, to a point where a given class can grow and grow until it is an un(re)usable blob or God Class. Often classes can be abused, and turn into Transaction Scripts wrapped in a class, or they have so many responsibilities it just doesn't make sense to reuse a class. The confidence in the code is already at a low due to the high amount of technical debt, coupled with pressing deadlines, means that the apparent reasonable choice for the developer would be to not spend any time trying to separate the behaviour they need (without breaking any of the existing application), but to ignore the existing code and start a new. Then later, with another pressing deadline, the same problem reoccurs and before long they have another God Class with poor code integrity, lots of technical debt, and a lack of confidence in the capability of separating the code.

In summary: bad OOP code can be worse than bad Procedural code.

*for about a year I took on the role of project assessment for a software house looking to take on existing legacy projects. I've seen some horrible, horrible code. :(


Top
 Profile  
 
 Post subject: Re: OOP and Reusability
PostPosted: Tue Jul 03, 2012 8:59 pm 
Offline
DevNet Master
User avatar

Joined: Mon Sep 19, 2005 6:24 am
Posts: 3587
Location: London


Top
 Profile  
 
 Post subject: Re: OOP and Reusability
PostPosted: Wed Jul 04, 2012 9:19 am 
Offline
Site Administrator
User avatar

Joined: Sun May 19, 2002 10:24 pm
Posts: 6887
Jenk,

With all due respect, I could certainly educate myself on all the nuances of a pile of smurf, but at the end of the day it will still look and smell like a pile of smurf (WSDL). I'm happy that you are content with your codebase and methodologies, however if the code is anything like magento, you can keep it.

_________________
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group