Archive for the 'PHP' Category

Upgrading PEAR - A moan and groan

Wednesday, 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?

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

Saturday, 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!

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 :) )

Grrr argghhhh! PHP consistency

Sunday, 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.

Presentation Layer - The Smart(y) Way

Monday, 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