Archive for the ‘PHP’ Category.

Headed to ZendCon

I’m headed to ZendCon tomorrow evening.  I get in pretty late Tuesday and will be at the conference all day Wednesday and Wednesday night (and in at Mozilla HQ on Thursday).   My talk, "Premium PHP", is at 4pm on Wednesday the 10th.

Looks like some people in the PHP blogosphere are already having fun out there, so I look forward to catching up.  See you there!

Do all frameworks really suck?

Ahem.  So anybody that’s known me for a while has likely heard me say something similar to what is quoted in Cal’s article about OSCON.  I should clarify because I hear jokes about "Tell us what you really think".

Choosing a framework to implement your web app is a trade off like any other design decision.  Let’s focus in on specifics and talk about what the trade off is that you make when you choose a framework.  Specifically, I’m talking about MVC frameworks in PHP.

Good things

  • Frameworks provide a common method of code organization, so developers can both a) get up to speed fast, and b) don’t have to think hard about how to architect an app.  They are effectively a standard for application architecture.  This is particularly useful when working with large dev teams or junior devs.
  • Frameworks encourage the separation of the presentation layer from the business logic, avoiding a frequent PHP worst practice where stuff is all mixed in together.
  • A framework can encourage secure coding through the use of dispatch architectures.
  • In general, frameworks avoid spaghetti coding.

Bad things

  • MVC is a design pattern.  As frequently mentioned by the good ol’ Gang of Four, every implementation of a design pattern is different, depending on the specific viewpoint of the implementor, and the specific application we are trying to produce.  This causes two problems.  One is that the implementor’s viewpoint is not necessarily the same as mine.  The second is that trying to shoehorn every app into the MVC structure isn’t always appropriate.
  • Most MVC frameworks have an intentionally flat design - models, views, controllers - and when codebases grow, you need to modularize for maintainability.  There are different ways to do this, but many frameworks don’t lend themselves well to this.
  • In the world of PHP, as with Perl, there is More Than One Way To Do It.  Specifically with frameworks, I believe Luke has been known to say there are 2.3 frameworks per PHP developer.  They are like content management systems or blogging systems.  We’ve all done it, sad to say.  The downside of this is that you lose a lot of the programmer speedup if programmers have to learn a new framework on every project.
  • Bloat is a problem in a lot of frameworks.  That’s what "makes the magic happen", but typically using a framework means lots of files getting opened (required/included) behind the scenes.  This slows down your app.  See for example Paul M. Jones’ (updated) benchmarks.  (That, by the way, is an excellent, excellent article that displays a good methodology for researching design decisions.)  I’ll also refer here to what I sometimes jokingly call Thomson’s first rule of software design: First, do the simplest thing that could possibly work.
  • It’s virtually impossible to retrofit an MVC framework on to existing code.  A lot of us spend most of our careers dealing with existing applications.

In summary:
Let’s be clear here: I am not recommending people write spaghetti code, or that they embed HTML willy- nilly in their PHP.  My recommendation in making any kind of architectural decision is to know what tradeoffs you are making and make an educated decision.  It’s important to remember that you can follow some of the basic rules of MVC and get a good number of the benefits without the bloat.  It’s equally important to remember that there is more than one way to architect a web app.

I’ll try and blog in future about a couple of other related topics: MVC in Rails compared to MVC frameworks in PHP, and templating systems.  (Unlike frameworks, all templating systems really do suck ;) )

OSCON Days 1 and 2

Tutorial days.  I had planned on blogging yesterday but Typepad, my blog overlords, had kind of a bad day along with a bunch of other companies hosted by 365Main.  The root cause of this failure was of course issuing a press release earlier in the day talking about how they had 100% uptime for the previous two years.  Murphy was listening.  I believe Terry Pratchett has something to say about standing in a shallow copper basin of water on a hilltop during a thunderstorm, cursing the gods.  Anyway.  It’s up now.

I attended a couple of tutorials: on Monday Wez and Marcus on Extending and Embedding PHP, and on Tuesday Michael Schwern on Simple Ways to be a Better Programmer.  They were at absolute opposite ends of the spectrum in a lot of ways: Extending was digging into C, and Better Programmer was largely about people hacks, but both were excellent tutorials.

In the morning Luke and I gave our tutorial on PHP and MySQL Best Practices (and I uploaded the slides).  I think it went ok but a little long - we had too much material as usual.  Email me if you have any questions, particularly about the bits we didn’t get to in the time.

I love OSCON; I always feel like my brain is expanding the whole time I’m here.  This time I keep hearing about parallelism, something I haven’t spent a lot of time on since doing pthreads stuff in  my final year at college.  I have been thinking the last couple of weeks that it’s time to refresh some of the things that I have long forgotten, and acquire some new skills.  OSCON is a great place for all of that.

OSCON Day Zero

Yesterday I arrived in Portland for OSCON and headed straight down to the PGDay.  I missed the start, but caught part of Rob Napier’s talk on "Build a PostgreSQL Web 2.0 Application in 10 Minutes", Theo Schlossnagle on PostgreSQL with Solaris, and Chris Travers talking about LedgerSMB.

Rob’s framework allows non programmers to build RIAs fairly simply, and seems to be aiming at the Filemaker or Access market, which is a large one that when we’re thinking about big sexy databases tends to get overlooked.   Theo talked mostly about the wonders of Postgres combined with ZFS (which obviously is something I’ve heard a bit about before) - it was a good talk.  I must admit I was flagging a bit during Chris’ talk, having missed lunch, but he looked at LedgerSMB internals.

Afterwards everybody headed up to the PGParty at the Courtyard Marriott. (pictures here) Overall a good lead in day.

Monday I’m spending the morning in Wez and Marcus’ Extending PHP tutorial, and the afternoon in various phone calls and doing a video podcast…should all be fun.  I’ll be taking it easy Monday night since our tutorial is at 8.30 on Tuesday, unfortunately.

Talk slides added

By popular request, I have added my most recent talk slides to this blog.  You can get them from the side bar (over on the right side there) or on the about page.

PHP Quebec slides posted

I gave my Writing Maintainable Code rant^H^H^H^Htalk this morning and have now posted the slides at http://omniti.com/resources/talks

Chris recorded it, so subject to quality I’ll post the audio soon.

This is a terrific conference - good talks, great location, and super organized - I had the feedback from my talk given to me by the organizers in summary form one hour afterwards.

Some highlights for me have been Robert Bernier’s pgpool talk and Andrei Zmievski on Vim for PHP Programmers.  Very good content in both.

PHP Quebec this week

This week myself, Chris Shiflett, and Alex Mikitik from OmniTI will be at PHP Quebec.  We are Silver Sponsors this time around.  Chris will speak on Thursday on The Truth About Sessions, and I’ll speak on Friday on Writing Maintainable PHP.  I’m looking forward to it - I haven’t been to one of Damian’s conferences before.  Hope to see some readers of this blog there.

We’ll be announcing some really exciting news at the conference, that I’ve hinted at before…I’m looking forward to the end of the week.

Breaking news: OWASP Spring of Code $$$ for security

Andrew Van Der Stock announced tonight at the first PHP Meetup at OmniTI in Columbia that OWASP have $100,000 available for security improvements in Open Source projects.  You heard it here first folks :)

Apply at http://owasp.org (when they put it up :) )

PHP Meetup between Baltimore and DC

I notice that when Chris announced the Columbia PHP Meetup, at least one of the commenters thought we were in South America.  Actually, the meetup is at the OmniTI office in Columbia, Maryland - about 20-25 minutes from Baltimore and about 45 or so from Washington D.C.  Please come if you will be in the vicinity, talk to other PHPers, eat pizza, and hopefully we can twist your arm to give a lightning talk.

We’ve been planning this for a long time so I’m pleased that it’s finally coming to fruition.  We have several big things afoot in the office at present.  Watch this space for something I’m really excited about shortly.

the pragmatic and the profound

First, the pragmatic: today I was interested to read Paul M. Jones’ framework benchmarks.  So often benchmarks are biased - and Paul would have every reason to be biased, considering he’s the author of Solar.  But he clearly goes through his methodology, and points out what he thinks might be the flaws in it.  An excellent read from a clear mind.  I’ll be interested to see the way the comments go, although I see from that and other blog entries I’ve been reading lately that RoR appears to have a number of comment spam bots (tongue firmly in cheek here).

Second, the profound: I was pleased to find online the complete text of C.S. Lewis’ essay The Inner Ring.  When I first read it (a few years ago now) it had a deep impact on me.  It was interesting to re-read this essay as my older, perhaps wiser, perhaps more bitter self.  If you’re not planning on clicking though, you may be swayed by the fact that the subtitle is "On Making Good Men Do Bad Things".  It’s about the desire to be accepted and how this turns men into scoundrels.  Sixty years old and as true as the day it was written.

In part:

To nine out of ten of you the choice which could lead to scoundrelism will come, when it does come, in no very dramatic colours. Obviously bad men, obviously threatening or bribing, will almost certainly not appear. Over a drink, or a cup of coffee, disguised as triviality and sandwiched between two jokes, from the lips of a man, or woman, whom you have recently been getting to know rather better and whom you hope to know better still- just at the moment when you are most anxious not to appear crude, or naïf or a prig- the hint will come. It will be the hint of something which the public, the ignorant, romantic public, would never understand: something which even the outsiders in your own profession are apt to make a fuss about: but something, says your new friend, which "we"- and at the word "we" you try not to blush for mere pleasure- something "we always  do."

And you will be drawn in, if you are drawn in, not by desire for gain or ease, but simply because at that moment, when the cup was so near your lips, you cannot bear to be thrust back again into the cold outer world. It would be so terrible to see the other man’s face- that genial, confidential, delightfully sophisticated face- turn suddenly cold and contemptuous, to know that you had been tried for the Inner Ring and rejected. And then, if you are drawn in, next week it will be something a little further from the rules, and next year something further still, but all in the jolliest, friendliest spirit. It may end in a crash, a scandal, and penal servitude; it may end in millions, a peerage and giving the prizes at your old school. But you will be a scoundrel.