Professional PHP Blog

PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.

Looking Towards the Cloud

May 2nd, 2009

Some people love their automobiles. They can tell you all all about their technical specifications. They buy upgrades and after market parts. Its a lifestyle and a hobby. I am not one of those people. For me an automobile is purely a means to an end. I am here, I want to be there. Having lived the last year without a car (my truck is in storage and will be for sale soon), I can say I don’t much care whether I get there in my car, or a taxi, or a zip car. This is the benefit of modern urban living, I suppose.

So, just as I look at an automobile as a means to an end, I look at servers as a means to an end. I guess that makes me a Software Guy. I know there are Hardware Guys out there. They’re doing great things and I’m thankful for them. But, for the most part, I am interested in what computers can do for us, not how they do it.

I don’t think I’m alone in my attitude. That’s why I think that computing as a commodity a strong future. We can leave things like data center efficiency to someone else and focus on the things that are really important to us. Oh, if you’re at facebook scale, you’re probably going to have to do serious cross stack optimization. And if you are at the hobby end, current cloud offerings may be pricy.

But, consider this. What can you buy with $100,000 per year? One programmer or 120 ec2 instances. (more with reserved instance pricing.)

Cloud Computing Versus Programming Talent

At a certain scale, cloud computing makes alot of sense. $100,000 is just a number. Oh, I know, you have this guy in Belarus and he works for less. But, the fundamental equation is the same. Programming is expensive and computing power is a commodity. Did I mention I’m a software guy?

Are you interested in how to use PHP in the cloud? Clay Loveless recognized the advantages of cloud computing early, jumping on ec2 as one of the early adaptors. He’s recently written a great Introduction to AWS for PHP Programmers. I’d encourage you to check it out.

15 Comments »

Holiday Tech Support

April 11th, 2009

I don’t see my family as often since I’ve moved to San Francisco. This weekend I’m home for the Easter holiday. Its nice to see everyone. Additionally, I have a backlog of tech support for my parents and grandparents. I’ve installed software purchased months ago, done updates that they weren’t even are of, installed a router and fixed rats nests of cables. I’ve restored TV setups to working order and am about to fix a vacuum cleaner. Are you the tech support guy for your family? What are you fixing this weekend?

No Comments »

Closures are coming to PHP

March 22nd, 2009

Dagfinn has a post looking at using the new closure feature of PHP 5.3. He compares using foreach for iteration versus array_map. “Interesting,” he concludes, “but not necessarily better than conventional alternatives.”

I agree for that case. Consider instead, a more complicated operation that requires a setup and a tear down after.

 
setup();
operation();
teardown();
 

Now what happens if we need to be able to customize operation? That’s common enough, one way of doing this is to create a template method.

 
class MyExample {
    function operation() {}
    function setup() {}
    function teardown() {}
    function doit() {
        $this->setup();
        $this->operation();
        $this->teardown();
    }
}
 

Now, we can subclass MyExample and override operation() with custom logic. This is well and good, but what the customization we need is fairly small. Creating a new class carries a certain weight. Especially if you are religious about one class per file.

 
class MyExampleExtension extends MyExample {
    function operation() {
        // custom logic
    }
}
 

Plus, you now have to deal with some creational patterns to make sure your custom class is used in the right context.

 
$myObject = $registery->get('MyExample');
$myObject->doit();
 

So, instead of encapsulating the pattern, its also very common to just copy and paste:

 
setup();
custom_operation1();
teardown();
//...
setup();
custom_operation2();
teardown();
 

But that’s not good on the duplicate code front. So here is an alternate implementation, but using a closure anonymous function as a callback.

 
class MyExample2 {
    function setup() {}
    function teardown() {}
    function doit($operation) {
        $this->setup();
        $operation();
        $this->teardown();
    }
}
 

The advantage of MyExample2 is that extending is that the setup and teardown pattern is encapsulated in one spot. You konw that if setup is called, teardown will also be called. But, extending the operation is very light weight.

 
$myObject = new MyExample2();
$myObject->doIt(function () { /* custom logic 1 */ });
// ...
$myObject->doIt(function () { /* custom logic 2 */ });
 

There is another significant benefit to this and that is locality of reference. Here, the custom1 logic and the custom2 logic appears in context, not far away in some custom class or function declaration. So you get encapsulation and reuse for the common code parts, but without the sprawl and overhead of declaring structures that will only be used once in a context far away their declaration.

Closures and anonymous functions decrease the activation energy to write good code.

That’s not to say that closures and anonymous functions can’t be abused. If you keep seeing the same logic over and over in an anonymous block, you should probably give it a name in the form of a class, method or function.

14 Comments »

php | tek Wrapup

May 26th, 2008

I really enjoyed myself at this year’s php | tek. The conference seemed even better than last year. Here are the slides from my talks…

Exceptional PHP
Coding for Success: Writing Software You’ll Be Able To Understand Next Month

Here are some of the books I mentioned…

Refactoring: Improving the Design of Existing Code
php|architect’s Guide to PHP [...]

7 Comments | Read the full post »

php | tek 2008

May 20th, 2008

Well, I’ve made it to PHP|tek in Chicago. I flew in last night, had a beer with Jason and then used the WiFi in the lobby to spin up an extra large EC2 instance (via RightScale) to do some benchmarks for one of my talks. I’m using the the XL instance because it [...]

4 Comments | Read the full post »

Sarah Snow Stever

November 23rd, 2007

I am very sad. Two weeks ago, my cousin Sarah had a stroke and died. She was 35, two years younger than me.
As kids, Sarah and I, (along with her sister Rachel) would spend weeks in the summer staying at my grandparents house, playing and doing the things that ten year olds do [...]

27 Comments | Read the full post »

Benchmarking PHP’s Magic Methods

November 4th, 2007

Larry Garfield has an interesting set of benchmarks covering many of PHP’s magic methods. His results correspond pretty well to my own benchmarks in the area. The thing to take away is that its not necessarily the overhead of the magic methods, but rather what you do inside them. Its hard to [...]

11 Comments | Read the full post »

The Endpoints of the Scale of Stupidity on Video

November 2nd, 2007

A quote from Cal Henderson (via simonwillison) presents a “Web Application Scale of Stupidity:”

| OGF (One Giant Function) —- Sanity —- OOP (Object Oriented Programming) |

The scale that Cal is talking about is actually better known as modularity:

| Few large modules —- Sanity? —- Many Small Modules |

If you haven’t listened to Alan Kay [...]

No Comments | Read the full post »

Working with PHP 5 in Mac OS X 10.5 (Leopard)

October 28th, 2007

Mac OS X is a great development platform for working with PHP. Leopard comes with Apache, PHP and many other development tools, such as subversion already installed. Leopard brings a much needed upgrade from Tiger’s tired PHP 4 to a very modern version of PHP 5.2.4. This is a guide for setting [...]

186 Comments | Read the full post »

Keywords and Language Simplicity

October 11th, 2007

Well, I like programming language comparisons, so how could I resist this chart (via) promoting the simplicity of the io language by pointing out how few keywords it has. The interesting thing about this is that Java and PHP are tied on this measure of simplicity with 53 keywords. Perhaps that reflects Java’s [...]

11 Comments | Read the full post »

« Previous Entries
  • Search

  • Subscribe

    Subscribe All Posts
    Subscribe All Comments
    Subscribe All Bookmarks
    Subscribe with Bloglines Subscribe with My Yahoo Add to netvibes Subscribe in NewsGator Online Add to Google
  • Share This

  • Categories

    • Agile Methods (14)
    • Mac (14)
    • Misc (17)
    • Open Source (14)
    • PHP (97)
    • Software Design (29)
    • Usability (14)
    • WACT (7)
    • Web Design (20)
  • Recent Comments

    • goto in PHP  45
      wawa, Riccardo Tacconi, Steve [...]
    • Building a culture of objects in PHP  6
      MagicCleanerU, hafizan, [...]
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)  125
      ad, aankun, Hutch [...]
    • Comparing PHP with other languages  22
      ?????, ?y??, Olivier Lalonde [...]
    • WordPress BBCode Plugin  23
      AgeRLeloglalK, smolenskiy, wow [...]
    • Looking Towards the Cloud  15
      Robin, Mohammad, tsst [...]
    • Code Coverage, Feedback and Open Source  3
      rwer, sdfsdf, mayur
    • Firefox Extensions for Web Developers  16
      Salman, Markus, Mitch [...]
    • php | tek Wrapup  6
      Livetek Software, PHP Guru, Scott [...]
    • OOP is Mature, not Dead  15
      Fernando, Chabrell Igan, deltawing [...]
    • nofollow and comment spam  4
      Mozzgggos, sss, Nataly Marshak [...]
  • Pages

    • Tags
  • My Other Stuff

    • Lively Debate
      My blog on Politics and non-technical topics
    • Web Application Component Toolkit
      PHP MVC Framework
  • Other PHP Blogs

    • Dynamically Typed
    • Jason E. Sweat
    • John Lim
    • Marco Tabini
    • Marcus Baker
    • Norbert Mocsnik
    • PHP Patterns
  • Archives

    • 2009: Mar Apr May
    • 2008: May
    • 2007: Jan Feb Mar Apr May Sep Oct Nov
    • 2006: Jan Feb Mar Apr May Jun Jul Oct Nov Dec
    • 2005: Jan Feb Mar Apr May Sep Oct Nov Dec
    • 2004: Apr May Jun Jul Aug Sep Oct Nov
  • Menu

    • Register
    • Log in