Upgrading PEAR - A moan and groan

March 12th, 2008

Well, let’s say i want to do something stupid and upgrade my PEAR packages. I go to the command line and run..

pear upgrade-all

and it … well fails for some packages because they’re alpha or beta.

Now far be it from me to moan but surely it’s more important to upgrade alpha and beta packages than the other packages?

Anyway fix it by upgrading each independently. For example;

pear upgrade Validate

fails as it’s beta - so append “-beta” on the end and hey presto it works.

pear upgrade Validate-beta

Genius! I just hope that maybe one day logic will win out and upgrade-all will mean upgrade-all?

Making MySQL OR performance better

February 28th, 2008

MySQL experts and Old SQL hands look away now. This is like teaching grannies to suck eggs, but if you’ve always had experience of advanced (which used to mean commercial) SQL databases then you probably don’t know this trick.

In the old days performance for OR clauses was pretty bad and a lot of DBMSs would ignore the index and start table scanning and performance would stink.

The old (and MySQL) way to get around this if the problem exhibits itself is to simply use a UNION and have each part of the OR on each side.So for example for table employee we need to find any employee where their name is ’stuart’ or ‘roger’ (i’m assuming we’re using an OR here - we could of course use an IN..).

The first version is the clear version

SELECT * FROM employee WHERE forename = 'stuart' OR forename = 'roger'

However, if you do an EXPLAIN on it and notice that it’s table scanning it’s trivial to re-write as a UNION

SELECT * FROM employee WHERE forename = 'stuart' UNION SELECT * FROM employee WHERE forename = 'roger'

Now if you know about your data (and the OR condition) then you can optimise a dash further. UNION merges the two result sets and checks for duplicate entries (de-dupes - just like a DISTINCT) before returning the values, but if you’re sure that the two sets won’t clash (and above is a great example) then use UNION ALL which ignore the de-duping stage.

So, why not always use a UNION? Well firstly it’s not clear and secondly there’s a duplication of code. Imagine if your OR clause was more complex (forename could be ’stuart’, ‘bob’, ‘roger’, ‘terry’, ‘june’) then that’s 5 repeats of the same statement. Throw in the fact that you’ll often explicitly mention the columns you want (remember i’m using a * in the SELECT clause for example only - try your best not to do this in real code of course) and that’ll you’ll have multiple joins then you realise you only want to do this if and when you get a performance problem.

Have fun and I hope not too many of you are sucking eggs at the moment :)

Java: (IMHO) Why independent application builders are shying away from it

February 23rd, 2008

It’s time for a little bit of opinion which I hope will feed into the developer usability of Java in future.

Recently we’ve been working with Java for a major client. They’re pretty typical really: they don’t use Windows on anything but the desktop and so Windows/Microsoft technology is out. They needed an “enterprise” quality language and framework so they chose Java EE over Microsoft’s .NET software stack.

Now before I go any further I need to tell you that I use VIM for most of my editing/coding needs - it’s quick and easy and for coding there isn’t an IDE that can beat it (although it’d be great if somebody could add some refactoring functionality). Using a test editor like VIM keeps the code clean and means that the cost of switching between IDEs for each language isn’t needed (for most tasks anyway).

Until recently we’ve been doing a lot of PHP for clients (with all the problems that brings - see earlier blog posts) so we’ve got used to a simple way of working. Build the database, PHP database tier, PHP Business Logic tier, and use Smarty for presentation, it’s easy and quick to do, then for unit testing we use SimpleTest (which I can’t recommend enough).

With the Java work it’s becoming impossible to work outside of an IDE; you’re either building xml files for descriptors, or bagging things up into EARs of WARs and then deploying to the app server. Now this isn’t a problem once you’re up and running and the environment and ANT scripts are in place, but if you’re working on a 5 day development for a smaller client that wants Java then you need to add another day for setup and environment matching - and that’s a large cost to most clients (that’s a 20% surcharge).

Now I’m not saying that Java’s much worse than .NET (esp. ASP.NET) but at least the Microsoft platform is a single platform and that makes things simpler, but even there with each incarnation of ASP.NET it seems to get more complex.

Java deployment needs a simple mode to build and deploy web based application, otherwise small clients just won’t and can’t afford to use it. How about a command line tool that you run against the top of the source tree, it builds it and deploys JSPs to the front end, and EJBs into the app server without needing a load of xml files? Is that even possible or realistic?

I originally loved Java because it was so much simpler than the alternatives; VB (with all it’s foibles and awful/non-existent thread handling) and C++ (with myriad libraries to use) it was simple and quick to do things. Then for the Microsoft crowd C# did the same thing and allowed them to leap forwards. Now both those frameworks are big (and bloated?) and there’s few of us who can quote what all parts of the framework libraries do.
What I think we’ll see in the coming future is more enterprises will follow the lead of smaller businesses and move to scripting languages for their internal and external application development. By doing this they’ll reap quicker turnaround and faster dev cycles. Some of the biggest IT firms on the planet are already doing this (google for example) so It’ll be interesting to see what happens.

PHP needs tuples!

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

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.

Grrr argghhhh! PHP consistency

September 16th, 2007

I really really hope that PHP6 is going to be more consistent than PHP5.

Who the hell would write a function called html_entity_decode and then call it’s opposite function htmlentities (that’s aside from the fact about why you wouldn’t just call them html_decode and html_encode without the entities bit)?

PHP needs to sort these crappy bits out as it’s seriously annoying. If it’s not the stupid argument conventions (is it haystack then needle or vice-versa?) then it’s the inconsistent use of the underscore in functions.
What PHP needs is a benevolent dictator for life (BDFL) like Python gets with Guido - somebody with a good indepth view of languages but has used the language in anger on big websites.

Python3000 is coming out soon and that language is going to be (as usual) super clean and slick - if PHP’s not careful then Python will pick up its marketshare. The only reason i think that people use PHP over Python is support from ISPs, and the theory that Python’s more “academic” and harder to learn/use… but that’ll change.
I like PHP - it’s a tool that gets things done but it needs to improve and fast.

Helping Tune SSAS2005 OLAP Cubes

September 13th, 2007

Today i was pointed at a good summary for optimising SSAS2005 cubes

In tandem you can use the “shared source” Visual Studio plugin - BIDS for more fine control of SSAS2005 - although use it with care if you don’t know what you’re doing!

OLAP MDX Optimisation Tip

September 12th, 2007

Ok Ok I know this is trivial but it’s saved more than my own bacon before…

You’ve built an OLAP (SSAS2005) Cube (and this isn’t your normal job) and some brain box has asked for a calculated member to be available (or alternately you’re adding this as a calc. member to a report and you want it calculated on the fly - see below it’s basically identical)

For example you want to find the ratio of the current bank accounts balance relative to all the others so you add a member of the ilk (in script form this is);

CREATE MEMBER CURRENTCUBE.[MEASURES].[Ratio of Account Balance]
AS iif ( IsEmpty( [Measures].[Account Balance] ),
[Measures].[Account Balance],
( [Measures].[Account Balance] ) / ( ROOT([Account]), [Measures].[Account Balance] )
),
VISIBLE = 1 ;

So, you run the cube in a report or the browser and suddenly that lovely cube response has shot up from sub-10 seconds to never coming back… what could you have done?

Well i’m assuming you’ve got a lot of data ™ - probably hundreds of millions of fact rows and you’ve now stopped SSAS optimising the search path and ignoring the empty bits. So, give it a hint and add the NON EMPTY BEHAVIOR (sic - behaviour - that gets me every time - colour becoming color i get but behaviour is just wrong) tip.

In the GUI simply select the requisite measure field, in the script tab add
NON_EMPTY_BEHAVIOR = { [Account Balance] }

voila! instant speed up and less heart attack!

(note: if this was an inline calc-on-the-fly type member then the full wording would be…

WITH MEMBER CURRENTCUBE.[MEASURES].[Ratio of Account Balance]
AS iif ( IsEmpty( [Measures].[Account Balance] ),
[Measures].[Account Balance],
( [Measures].[Account Balance] ) / ( ROOT([Account]), [Measures].[Account Balance] )
),
NON_EMPTY_BEHAVIOR = { [Account Balance] },
VISIBLE = 1 ;

SQL Server Reporting Services - doing custom subtotals

September 12th, 2007

Chris has an excellent post about custom subtotals using INSCOPE that has been pretty helpful to me.

Using a Matrix with OLAP cubes can sometimes be a bit painful and icky, but this technique makes adding additional info really easy.

Now all we need is access to a proper ternary operator instead of that horrible IIF vb-istic construct and we’d be laughing.

Presentation Layer - The Smart(y) Way

June 25th, 2007

Using PHP? Using Smarty? If not then why not?

Templating for presentation is often a pain - on the windows platform i’ve used vanilla ASP, and ASP with XML which is then transformed into XHTML using XSLT. With ASP.NET again the same schemes, plus the use of themes. On other platforms JSP is a similar story. On all platforms CSS is heavily used but there’s still something missing and i18n (internationalisation) was still more difficult than it should be… and working with design agencies was a nightmare (as they had to hack XSLT or look at ASP/ASP.NET/JSP pages).

The solution is proper templating and i tried a few and hated them all… Smarty is the exception - if you’re using PHP and you’re not using Smarty then you’re missing a trick.

The intro guide is great, the plug-in support is nice and the template files are easy for even the most hardcore dreamweaver based graphic designer to understand.

Check it out at http://smarty.php.net for more info