OOP and Reusability

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Re: OOP and Reusability

Postby Chris Corbyn » Sat Jul 14, 2012 7:07 am

This thread has gone way off-topic now, but I just wanted to chime in with my thoughts regarding TDD/BDD. As somebody who actively uses TDD on all code on a daily basis, I find it ludicrous that another TDD'er could suggest that using TDD alone eradicates *all* bugs. That is just frankly absurd. Even with 100% test coverage (and mutation testing), you will still run into edge cases where combinations of inputs fall outside of some expected range, unless you're writing extremely simple applications, or have an infinite number of test cases to cover all possible inputs. Yes, you can prove that the bug exists once it has been found, then ensure it doesn't come back by using a test, but you can't, with 100% certainty know that it will never exist, if you haven't specifically tested the edge-case inputs. We have few bugs, but we do run into them, always at the extreme edge cases. We find out about them through our exception-tracking service (Errbit) and add test coverage as needed.

With regards to the discussion of OOP vs. Functional Programming, I have no idea how WordPress came into the discussion. WordPress is not functional. It may favour global functions over classes, but it is more generally imperative in design.

I don't think OO and Functional programming concepts differ vastly in terms of code re-use, though I can see how that thinking may come about when functions are not coupled with an associated state container, making them more generally applicable in different problem domains. Good object-oriented languages allow very fine-grained code re-use through object-models that support mixins/traits. Take a look at Ruby's Enumerable module. Just about everything you can iterate, map, reduce, zip, partition etc etc in Ruby has done nothing more than define an "each" method, then mixed in the Enumerable module to get the rest of the behaviour for free.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 8:57 am
Location: Melbourne, Australia

Re: OOP and Reusability

Postby Jenk » Mon Jul 16, 2012 6:52 pm

It's the ATDD and BDD that removes all the bugs - i.e. not "using TDD alone" :). TDD just helps us get there when filling in the very minute gaps that the specs don't directly fill. To us, TDD is "this card shuffler should randomise the order of this pack" whilst BDD and ATDD take care of the "given I've got a pack of cards in a contiguous order, when I shuffle those cards, then those cards should be in a random order." I hope the meaning behind the difference between those statements is clear.

We also advocate CQRS, and Event Sourcing. It is absolutely imperative that everything is broken down to the smallest possible detail with the person(s) who understands what it is that is required - not a BA or Manager, but the actual expert of the domain. No room for "just simple CRUD" at all here. Ergo, there is no way for there to be erroneous input. Must have complete and concise capture of the intent behind an operation. There is no "allow admin to update a user." There is only commands and events for "changing the name of a user because they have married" or "changing the name of a user because they have divorced." It's as complex as complex can be, but we must understand it all to develop it. Number of tests is exponential to complexity of software because rule number one of BDD, TDD, CQRS is to eradicate complexity. Complexity is compacted simplicity. Is it complex? Then take smaller bites.

A "Bug" is unintentional behaviour through oversight or mistake when developing. It's very, very difficult (I'm only refraining from using "impossible" due to the uncertainty principle here :p) to do either of those if employing BDD (and employing it "properly".)

4, nearly 5 years bug free on a very large system spanning multiple technologies and platforms; interacting with multiple systems including many 3rd party systems, and used globally by 120,000+ users for real time transportation of pharmaceutical supplies, with 2 teams of 8 developers working full time adding new features, both teams limited to 3 stories in "work in progress". It's not simple software.

Anyway... I hope that isn't too "smug".. I really don't intend it to be, so apologies if it is. I replied to give some light onto what benefits resusability in OOP has, and that, like all things in life, it can be "done badly" and then I saw Benjamin's post and just couldn't resist responding to his misunderstanding(s) but I can see I've upset him and possibly others, so I'll return to lurking again.
User avatar
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: OOP and Reusability

Postby Benjamin » Mon Jul 16, 2012 10:38 pm

Jenk I'm not upset, don't worry. Just have a tendency to say what's on my mind ;)
User avatar
Site Administrator
Posts: 6865
Joined: Sun May 19, 2002 10:24 pm


Return to PHP - Theory and Design

Who is online

Users browsing this forum: 2u0ci1hnhc and 3 guests