Archive for October, 2007

PHP needs tuples!

Saturday, October 20th, 2007

I think the headline just about says it all.

PHP makes things dead easy by using arrays as straight arrays and hash tables, and there’s a PHP idiom to pass multiple parameters back from functions using them too. This (IMHO) would be better served with support for tuples.
An example probably helps;

Imagine i have a routine that needs to maintain backwards compatibility. It used to just return an array of values retrieved from a webservice, but now for some pages it needs to return that info (limited in scope) along with details of how many records there are in total (so they can be paged).

So old client calling code looked like

$data = $someobj->GetData();

and some newer calling pages want to return all the detail (so they pass a true in), well they have to do this

list ($data, $totalrecords) = $someobj->GetData(true);

well let’s imagine somebody does something stupid had been passing a parameter that evaluates to true (incorrectly) - after all PHP has let them because the parameter wasn’t used (and they turned warning messages off? - not that uncommon unfortunately), they don’t expect a change; it used to return an array of data… now they look at the array and there’s always two entries in there and the page is broken.

Now if PHP had tuples with a defined syntax then that could be handled nicely, and old (and bad) client calling pages/code would break (as it should - in the above circumstance it could “work” and render stuff to the page … eek!).

In Python i can say

data, numrecords = someobj.GetData(true)

here a tuple’s returned and unpacked. For the old client code if it was saying

data = someobj.GetData(true);

that now has a tuple in it.. and that’s a specific object type, so iterating it using index numbers would break.

Now, that’s a (quasi)practical example but the truth is it just makes sense for functional languages as tuples mean something different to arrays (note: i’m not saying php is a functional language so don’t flame me - it is however a scripting language with some functional attributes).

I’m just hoping zend add them at the next iteration (and take account of the rest of my moan list :) )

Buzzword Paybacks

Tuesday, October 2nd, 2007
After reading the latest edition of the Architecture Journal i’ve changed my views on buzzwords.Previously I enjoyed hearing “Synergy”, “Synergize”, “Singing From The Same Hymnsheet” and those wonderful terms and words. I’d even jump up in meetings shouting “Bingo!” and enjoy the applause, adoration, and career destroying effect it had. These days they’re killing me.

What I thought would be useful was to find a way to remove these words and phrases from the vocabulary. Finally I think i’ve found the solution: the punisherizer(er).

For every buzzword or buzz-phrase that somebody uses any others in the vicinity have the responsibility to hand out a standardised (that’s not a buzzword btw) punishment. We’re compiling the table at the moment, but here’s a sneak preview to get you all warmed up.

* Synergy/Synergise - automatic castration using wooden implements (admittedly this means we all have to carry around a castrating wooden tool - but no pain no gain!)

* Sing From The Same Hymnsheet - (this needs pre-planning). Record about 10 hours of the Ricki Lake or Jeremy Kyle show, superglue the perpetrator to a sofa infront of a TV, superglue their eyes open and start recordings. I recommend a punishment cycle of less than 20 hours as this punishment can cause irrepairable damage.

* Thinking outside of the Box - find a large box made of concrete, place offender inside, deposit into deep river or sea.

* Leftfield - wait until winter, tie person naked to a tree in a field. Leave in a “spartan baby” type way until problem is solved

* SOA (or the more verbose “Service Oriented Architecture”) - find a drawer with a good solid motion, deposit something delicate inside it, slam repeatedly (note: if the same person has misused the words “extreme programming” or “agile development” too then feel free to superglue pins to the inside of the drawer…

Some people don’t think these punishments are commensurate with the crime - but please remember: don’t be gentle or they just won’t learn, after all you can’t make an omelette without breaking a few eggs (damn… sorry i’m just off to apply electricity to my earlobes as punishment for that phrase).

As an easier alternative you should just invent new idiotic phrases that are guaranteed to annoy and confuse - full marks go to Neil of Winters Consulting for his brilliant “strapping the lllama” which began to be used within a certain large organisation (that was buzzword crazy) we were working with.