serialization without pity

You may have guessed my PHP development philosophy from something I wrote recently, but an interesting question at work yesterday showed that I need to put it in words.

If there is something difficult to do in PHP, there is probably an extension somewhere that allows PHP to push it to another layer. If that is something that can’t be pushed to another layer, than PHP probably has a built-in function or best practice to handle that case. Find that extension, function, or best practice and never choose one where another is better.

At work, the problem was, “Well if we weren’t so big, I’d have done all this on the database, which probably means that PHP shouldn’t be solving this problem.” In other words, if the scale was small, the database, not PHP, would have been the obvious place to solve the problem we were having. But the scale we operate is too large for a database so it becomes a problem. A solution to the problem on this scale written in PHP would not be a good architecture decision. (I’d pay for it down the road.)

That explains the first part of my philosophy, but what about the second?

[autoload, quirks, and session serialization after the jump]Continue reading

His conversion is almost complete

I used to work with a guy named Haiping, a former developer at Microsoft who was hired just two people before me at Plaxo. He has some crazy C++ skills as well as is pretty damn good at that headshot thing in PC first person shooters. Last time I was in South Bay, I stopped by Plaxo and talked to him. Later that evening, I went to the Facebook Tech Tasting and met him again. Only this time, his tag said “Facebook.” Between those two times he had changed jobs!

The great thing about our former company, is that you get card updates. I like to accept/reject mine over the web interface and read this today. Read his Work Card Message:

My friend Haiping flips his job

A C++ engineer switches to PHP. A windows user switches to Mac. Now all I have to do is convince him to get a Nikon camera. Now all they have to do is port Day of Defeat to the Mac.

The Shu Ha Ri of strings

In a discussion on the speed differences between various types of strings, I was completely misunderstood (or ignored).

Sad.

George told me his all-time favorite PHP talk of mine was the first one I gave: “OOPs: The PHP Fear and Loathing Guide to Basic Object-Oriented Design.” Perhaps one reason may be is this segment (click the image below a bunch to playback the slide deck):

Shu-Ha-Ri is the way you learn in Aikido, but it applies to everything. For those who didn’t play back the above slidedeck or understand it, here is the ideas I want you go have in your head:

  1. Shu – Hold – Copy
  2. Ha – Break – Deconstruct
  3. Ri – Leave – Transcend

Shu: Use the single quote

Here is a summary of results a PHP developer who leads the unexamined life:

  • Single quotes are always faster than double quotes but the difference is negligible.
  • Function parameterization is faster than concatenation (use commas over periods when calling print or echo).
  • String concatenation is always faster string interpolation.

But this can be understood with a simple Ri maxim:

“In PHP, always code for readability first.”
—Me circa 2004

I’ll explain how to get from Shu to Ri in gory detail below and answer a couple of my favorite interview questions in the process.

[Gory details after the jump]Continue reading

Vote for Andrei

This is a shameless plug for my friend Andrei.

Vote for Andrei

Andrei is writing something that forms the very essence of my future employment: PHP 6, and more specifically, unicode support in PHP 6. ICU in PHP is three meaningless letters about three other meaningless letters to most of you. I get that. Even though this meaninglessness stuff has 60% market share and powers sites like Yahoo!, Wikipedia, WordPress, Facebook… (The “Vote for Andrei” generator above was written in PHP. It powers the websites for JPG Magazine and Flickr below.)

So when I say that it’s really important to keep this guy happy, please believe me. Think about the last time that you visited to the above websites. You wouldn’t want them to suck do you? If your native language is not English, then you would want them to work in your country right?

Luckily, photography is infinitely more accessible than the stuff that pays the bills. So please, take some time off from your day of ignoring my blog posts to do the world a favor and vote for this photo on JPG magazine (and tell your friends to too):

It’s a great photo and utterly appropriate with the theme of the month. My only complaint with it is he should have gotten with the bandwagon on photos like this and LOMO’d the sucker beyond recognition. I can almost recognize what it is.

[Andrei and photography after the jump.]Continue reading

My programming pattern maxim

There are few people this side of Harry Fuecks who have rode the php design patterns money train as much as I have. In fact, programming patterns have been very good to me: they’ve provided trips to exotic locales, paid for my conference admission, impressed all the hot women…

Well maybe not that last one.

But Alejandro’s recent spate of GoF patterns on DevShed, besides being a blast from the past, made me realize that practicality hangs over my Pattern Bubble like the Sword of Damocles, pointedly showing just how oppressive programming design patterns in PHP are.

Time for a new rule:

“With few exceptions, by the time you deduced what a pattern is from its clever name, you could have just coded it.”
—Terry Chay, 2007

and my original inspiration:

“PHP isn’t Java. Deal.”
—Terry Chay, 2003

[The Flyweight makes an appearance after the jump]Continue reading

Interesting PHP factoids

It’s times like these that I wish someone just told the reporter that PHP is a programming language for web development that has a larger marketshare than Java J2EE and Microsoft dotNet combined:

[Web 2.0 technologies] also mean applications can be built much more quickly, says Mr Boloker. He is a big fan of PHP, an open-source scripting language which makes building mashups even easier. Originating in Greenland, PHP is now managed by an Israeli company called Zend.
Sydney Morning Herald

I didn’t realize that Rasmus wasn’t in Canada when he wrote PHP and that Cupertino is now in Israel.

Good to know.

Oh yeah, it’s nice that they’re allowed to use Apple Macintoshes in IBM, I didn’t know they’re so generous. Will they be taking his away with the Intel switch?

Other than that hilarity, thank you Dave Boloker for plugging PHP. Now I can go around saying that the former chief of Java Technologies at IBM Software Group is a “big fan of PHP.”

Rock on.