vim folding

My favorite vim setting

// vim:set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker syntax=php:

has the unfortunate side-effect of causing others to complain about the fact that my source code is “folded.” The problem is that some people who are only vim-users-only-when-working-on-a-remote-machine have a small learning curve when they see a page that looks like

<?php
// vim:set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker syntax=php:
+-- 12 lines: docs -------------------------------------------------------------
+--  6 lines: imports ----------------------------------------------------------
+--154 lines: WidgetProviders --------------------------------------------------
?>

But with about a minute, training yourself how to navigate vim folding will pay itself off handsomely for those of us who don’t use IDEs or do fancy stuff like exuberant ctags.

[quick fold tutorial after the jump]
Continue reading

Another Search Startup

A friend sent me the homepage of yet another stealth search startup. This company plans on using NLP.

My comment:

“Hmm, I should send [the URL] to Dave. He loves it when a bunch of braniacs get together to make an ASS [Another Search Startup] of themselves.”

New term I just invented. I hope it catches on. 🙂

Database Abstraction vs. Data Access

Alejandro Gervasio has an excellent article on using polymorphism to create a database abstraction layer.

Basically if you are wondering why or how PEAR DB, MDB, ADOdb, or PDO use the Factory pattern to provide database abstraction this walks you through it.

Maybe five years ago, this was a mind-blowing idea. But perhaps we should call into question whether this is an unnecessary abstraction.

[Database abstraction vs. Data Access after the jump]Continue reading

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

YASNS privacy

Andrei pointed me to this article trying to find the next MySpace.

Look at the sidebar: the numbers are pretty impressive when you consider what ad revenue that represents.

Multiply was an analyst pick because it has “strict privacy controls and lets people set up networks that can only be viewed by people invited to their group.” Having worked at a company with the strictest privacy policy in the universe, I’ll disagree with the pick.

In light of my recent Haiku fun:

Network Privacy?
Live quiet desperation
in obscurity.

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.

Facebook @ SXSW

When did SXSW become the “It” conference? I remember when people in the Valley would say “I have to go to SXSW” followed by a sigh that reminded me of how I used to approach mowing the lawn.

First comes the music, then comes the money, then come the geeks? Or is this another excuse for LA to jet to TX for some real BBQ?

In any case, if you are there, you might want to attend the the Facebook party tonight. Apparently, like an acquaintance’s Burning Man tent, there’s going to be Red Bull on the house.

Be sure to register now to get the super secret location sent back to you. If you are bored and sober, ask the Facebook people what’s up with the FQL thing—all my mad, non-existant SQL skills transferred to an API? Or, why salt every request in the session with a ref counter provided on client side?

Be sure to get them good and drunk before doing so. The answers might be halfway interesting then. 😀

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