Advise for an Aspiring PHP Developer

Posted 11/2/2005 By Jason

A self described “aspiring PHP developer” recently asked me for advise on how to improve his skills since there were no PHP offerings at his school. Here was the advise I gave him.

Welcome to the world of PHP.

I have learned the most by following and participating in the discussion at the
SitePoint advanced PHP forum
(http://www.sitepoint.com/).

There are two coding techniques you can study that will pay great dividends:
Unit Testing (and in particular Test Driven Development, see
http://simpletest.org/ and http://www.testdriven.com/) and the use
of Design Patterns (see
http://en.wikipedia.org/
http://home.earthlink.net/~huston2/dp/patterns.html
and http://www.phppatterns.com/).

A project to investigate which combines much of this is WACT
(http://phpwact.org/).

Some good blogs:
http://www.procata.com/blog/feed/rss2/
http://www.lastcraft.com/blog/wp-rss2.php
http://netevil.org/feeds/rss.xml
and many others you can find through
http://www.planet-php.net/.

I would be remiss in not letting you know I have written a book on these
subjects as well :)
php|a

Hopefully that gives you something to chew on!

Looking this over, I realize I left out a critical resourse of the PHP Manual and the associated user comments, a great resource for PHP developers.

What advise would you give to an aspiring programmer?

   

phppatterns revived

Posted 10/27/2005 By Jason

If you are an aficionado of Design Patterns, and of PHP, then you may have noticed the hosting problems, and times outright disappearance, of the phppatterns website. With some hosting assistance from Jeff, phppatterns is back online. It is nice to see this valuable PHP and Design Pattern resource back online. One significant visible change is the use of Docuwiki as a back end (no comment on the chosen color theme from me ;), hey I am a programmer, not a designer, also).

Harry has also posted a detailed review of my Guide to PHP Patterns book. This is the most thorough review of the book I have seen to date, and I am happy to report that almost all of the feedback I have seen on the book so far has been positive.

   

Load Gun, Point at Foot, Shoot.

Posted 10/13/2005 By Jason

Sometimes it is hard to believe what some people do. I read on Derick Rethans site this post about a Fan Mail. This kind of a response saddens me as I think people are starting to forget their manners.

One thing people seem to constantly forget is that open source projects like PHP are fundamentally volunteer efforts. One can argue that Derick works for EZ Systems, and they derive revenue from PHP and pay him to work on PHP, but the fact is I know Derick spends significant amounts of “off the clock” personal time working on PHP — deep internal core parts of PHP that you and I use every day. Derick has freely chosen to work on PHP, and freely donates his time and effort to the endeavor.

People are rational beings. Everything we do is “good” in some manner, because that is how we are wired to motivate ourselves to do anything. We may disagree on the realized benefits or the percentage of the “good” we will receive from any given actions, but we should always try to remember that another person is trying to do the right thing from their perspective.

To the issue at hand, backwards compatibility breaks suck. This issue was not communicated very well, but if you were diligent, you could find areas where this was talked about on the internals list (for example here).

I think some of the core developers got a bit tired of responding to this particular issue, and started to push the “send a patch or forever hold your peace” line. I don’t think this particular line of thinking does the community a service either. I like to think I have contributed to the PHP community as a whole through discussion of use of PHP, example of code, contribution to projects written in PHP and by writing books and articles on PHP. All this aside, I have never contributed a line of C to the core of PHP, and I think there are many others in similar positions. Similarly, I think many people work hard to put together detailed bug reports, and these people are also contributing to the PHP community as a whole, though not in the same manner as the core developers.

Overall on this issue, I want to express my thanks to Derick for the many long hours he has put into making PHP a better language, and a great productive tool. Thank you Derick.

   

A Summers Work

Posted 8/18/2005 By Jason

I had a chance to summarize many of the projects I worked on this summer in a single photograph.

Books on chair

The biggest thing is the hardcopy versions of my book finally arrived! After nearly a year of nightly toil, it is quite a relief and satisfaction to hold them in your hand.

The books are resting on a ZCE tee shirt I won in a contest filling out a survey regarding the certification process. I’ll give you three guesses what shirt I will bring to the next PHP conference I attend (and the first two guesses don’t count). I passed the ZCE test at the php|tropics conference, so the shirt feels like a reminder of the efforts which culminated in my presentations there.

Lastly, this picture was taking in our three seasons room. After six years of staring at 2×4 framing, I finally decided to finish off this room. Earlier this summer I pulled runs of Coax and Cat5 to receptacles at the outer corners of the room (and wired in an outdoor GFI outlet on our deck), then insulated and dry walled the room. As you can see from the picture, I still have yet to finish the first round of taping and mudding.

   

Hacker Logo

Posted 8/14/2005 By Jason

An interesting idea to promote the hacker, not cracker, community as a whole. Associate it with the glider pattern from the game of life as a logo.
hacker emblem

I found this here via the Ruby general mailing list.

   

Iterator Article in July php|architect

Posted 7/21/2005 By Jason

This months php|architect magazine has one of the chapters of my design patterns book as the lead article. You can download just the article as the sample chapter for the book.

I think the iterator chapter does a good job of being a representative sample of the book. I had both php4 and php5 code example, show a “pure” Gang of Four style iterator, as well as a more abreviated API version, and showed a bit of how to use the SPL iterator interface. It has a splash of UML, tons of code and SimpleTest based unit tests as well.

If you have any questions or feedback, feel free to leave a comment here, or post a message to the php|architect forum.

   

MVC Song

Posted 7/10/2005 By Jason

The MVC Song and the credit for me stumbling across it :)

Hilarious. Educational. A must listen.

   

The Wait is Finally Over

Posted 6/27/2005 By Jason

It is official, I am now a Zend Ceritified Engineer. To quote my notification:

Dear Jason Sweat,

Congratulations on passing the Zend PHP Certification exam!

As a Zend Certified Engineer you are now among an elite group that leads the
growth of PHP.

Now I should figure out how to work this logo into my WordPress theme 😉
ZCE Logo

I took the exam one morning during the php|tropics conference. There was a recent thread on SitePoint where I mentioned what I thought about the exam itself (my post is #46). Many thanks to Marco for footing the bill for the exam.

Looks like Paul read his email before me and got “first post” in the blogosphere from the newly minted php|tropics ZCEs.

   

I am a Statistic

Posted 6/25/2005 By Jason

I followed up on a post from Ben Ramsey on a MIT survey of bloggers, and did my part to contribute to science 😉

Take the MIT Weblog Survey

   

A New SitePoint Mentor

Posted 6/22/2005 By Jason

As stated in this thread, SitePoint has a new Mentor… me :) This means I get this shiny orange badge Mentor Badge above my avatar. In order to maintain this honor, I have to continue to be adicted to the SitePoint forums (in particular, my favorite the PHP Application Design forum), and I have to continue to behave myself.

Hopefully this will in some small way give back some to the community which has given me the opportunity to get to know several people whom I now consider good friends: Marcus, Harry, and Jeff.

   

Offical Patterns Book Announement

Posted 6/21/2005 By Jason

The book is getting closer. Yesterday we had an official announcement on the php|architect website, which pointed to the order page. It looks like Marco is giving a 10% preorder discount, so everyone should order 10 copies today, and effectively get a free copy. 😉

I would have also emphasized unit testing in the blurb. While there are a few PHP books out there which have chapters or sections on unit testing, I don’t believe there is any other book which emphasizes the practice as much as I have. Unit tests are not only present in the code download for each chapter, but are integral to the explanations in each chapter as well. Many times when I present examples of working code, it is within the context of a unit test. I also tried to explain the basics of Test Driven Development, and have a few examples shown using TDD iterations.

The Adapter chapter is off to layout so we are down to the last few chapters! I am really looking forward to holding the dead tree edition :)

   

The Specification Pattern

Posted 6/15/2005 By Jason

Last night I sent my chapter on the Specification pattern in for layout. This passes the > 50% mark for chapters through editing and off to layout as well.

This chapter was fun to write because it strays a bit from the Gang-of-Four/Fowler PoEAA design pattern mainstream. Fowler has written some articles on this pattern and Eric Evans covers it in some detail in “Domain Driven Design”. I first show a “hard-coded” example, and then a parameterized specification which can take a WACT DataSource object as the item being tested. The last example in the chapter shows how to create a composite structure of concrete specification objects to act as a “Policy”.

The chapter is an evolution of some early work I did with the Specification pattern in this thread.

By popular request, here is the complete table of contents:

  1. Preface
  2. Programming Practices
  3. The ValueObject Pattern
  4. The Factory Pattern
  5. The Singleton Pattern
  6. The Registry Pattern
  7. The MockObject Pattern
  8. The Strategy Pattern
  9. The Iterator Pattern
  10. The Observer Pattern
  11. The Specification Pattern
  12. The Proxy Pattern
  13. The Decorator Pattern
  14. The Adapter Pattern
  15. The ActiveRecord Pattern
  16. The TableDataGateway Pattern
  17. The DataMapper Pattern
  18. The Model-View-Controller Pattern
  19. Conclusion

Appendices:

  1. Patterns Quick Reference
  2. SimpleTest Testing Practices

update: Had some funny characters in my summary, removed them to see if it helps peoples feeds.

   

Happy 0xA B-day PHP!

Posted 6/8/2005 By Jason

Chiming in with the chorus, many thanks go out to Rasmus, and every other contributor to PHP, for creating a phenomenon.

Following the tradition of the other PHP anniversary posts:

What was I doing 10 years ago?
I was working for a small engineering firm in Iowa doing process control work in the steel industry. Our control system used artificial neural networks to optimize the control of electric arc furnaces. This work expanded into SCADA (supervisory control and data acquisition) and led eventually to me displaying this process control data on web pages via ASP and IIS.

When did I get involved with PHP?
In 2000, I was looking for a free—as in beer—way to create dynamic web pages for a partnership whose accounting I maintain. My UNIX administrator at work turned me on to the LAMP stack and I have never looked back. I have brought PHP into use for both web page development and batch scripting at work, and have written several articles, books and numerous presentations on PHP.

Happy birthday PHP, and many happy returns. Thank you PHP team for endless hours of toil.

   

The Singleton Chapter

Posted 5/26/2005 By Jason

I was reviewing the editing of the Singleton chapter last night. It was kind of interesting to look it over again, as I originally wrote, and had the tech review performed, on this chapter back in December of 2004! Looking it over again I am pretty proud of the decisions I made in writing it. One important decision was to not make the Singleton pattern the first design pattern explained in the book. The actual sequence of chapters up to this point is:

  1. Preface
  2. Programming Practices
  3. The ValueObject Pattern
  4. The Factory Pattern
  5. The Singleton Pattern

So the Singleton pattern is the third pattern covered in the book. The Programming Practices chapter gave me a chance to introduce Unit Testing and Refactoring, which is very important considering the heavy use of SimpleTest throughout the rest of the book for unit tests of the code. As I mentioned in an earlier blog entry, the unit tests are not just included in the code download, but integrated directly into the prose and flow of each chapter. The ValueObject pattern discussion gave me a chance to review references in PHP4 and object handles in PHP5 in much greater detail, and doing FactoryMethod next lets me allude to the fact that the Singleton is essentially a specialized Factory which only returns a single instance of a class.

In the book I try to give equal coverage to PHP4 and PHP5, but this particular chapter I spend much more time with PHP4 examples, as having private constructors in PHP5 make implementing the pattern relatively easy. I cover several possible implementations, and highlight the fact that the Zend 1 engine does not store references in static variables (as noted in the manual).

I briefly cover the MonoState pattern here as well, since they end up exhibiting similar behaviors, and you can do some neat code with reference —non-object related references!—to implement the MonoState pattern.

   

Book Update

Posted 5/24/2005 By Jason

This post is just a quick update on the status of my book, PHP Architect’s Guide to PHP Design Patterns. Marco fired himself as editor…because he found a more suitable replacement. We are still kicking through the editing review and are about 20% of the way through the book, and are trying to process around one chapter a day. This is the final pass before layout.

As I understand it, the book will be available in PDF on the php|architect site very quickly after it has been through l lay out. The turnaround time for the print runs is minimal as well. To the best of my knowledge, we are still targeting June for having it available.

Marco has been hot on my tail with regards to some ideas to market the book. Keep tuned here for further information on this subject :)

   

Just the Facts Ma’m

Posted 5/18/2005 By Jason

What does a PHP geek do when confronted with the task of generating practice math problems for his eight year old daughter? Script it, of course. Madeline wanted to practice addition, so she gave me a crayon and told me to write down 100 math problems consisting of adding two single digit numbers.

A “better” solution lept to mind immediatly:

A class to store and render a “fact”:

<?php

class Fact {
    protected $top;
    protected $bottom;
    
    public function __construct($t, $b) {
        $this->top = $t;
        $this->bottom = $b;
    }
    
    public function render() {
        return '&nbsp;'.$this->top."\n<u>+".$this->bottom.'</u>&nbsp;';
    }
}

?>

Generate some facts and store them in an array:

<?php

$facts = array();

foreach(range(0,9) as $top) {
    foreach(range(0,9) as $bottom) {
        $facts[] = new Fact($top, $bottom);
    }
}

?>

Make sure they are in random order:

<?php

shuffle($facts);

?>

and render them into a table for easy layout (what can I say, it was a two minute hack):

<?php

echo '<table border="0" cellpadding="9">';

foreach(range(0,9) as $tens) {
    echo '<tr>';
        foreach(range(0,9) as $ones) {
            echo '<td>', $facts[$tens*10+$ones]->render(), '</td>';
        }
    echo '</tr>';
}
echo '</tr></table>';

?>

fresh, randomly ordered fact sheet ready for printing.

   

Here is the Test Driven Development in PHP presentation from php|tropics. You can download either the zip or tarball flavors. In each is the PowerPoint presentation and the code files with unit tests I used when writing the presentation.

This presentation also went well. I went out on a bit of a limb and did some TDD live for about 45 minutes near the end of the session. We all decided to work on a MySQL driven Guestbook. Since there were about 30 or so people who were willing to hang around for 20 extra minutes while we finished the example up, I think that is a pretty good testament to the presentation, particularly considering the beautiful Cancun sun which was minutes away from all the dedicated attendees.

   

Here is the Design Patterns in PHP5 presentation from php|tropics. You can download either the zip or tarball flavors. In each is the PowerPoint presentation and the code files with unit tests I used when writing the presentation.

I felt this talk went fairly well, particularly considering it was in the same time slot as part two fo Chris Shiflett’s Security presentation (which we all know how that one drew a crowd at php|works in Toronto last fall).

   

Breaking the Silence

Posted 5/2/2005 By Jason

Long time, no posts. I have been very busy writing my PHP Design Patterns book, and have left little time for (self|family|blogging|other activities).

First of all, every chapter of the book is done!! Every chapter had to be written, sent to tech review, edited, and then sent to the editors. The final chapter came back from tech review a week ago Sunday, and on Friday night I sent it off to the editors. As I understand the rest of the process, I have to do one more approval of the final layout, then after a short turn around, it goes up as a PDF on the php|architect website. Only a week or two after that, it will be available in hardcopy. Down to the wire, but I am hoping to see the dead tree edition by php|t.

I am really proud of the work which went into the book. The book is basically a pattern catalog. For each pattern, I tried to select an example which exemplifies the pattern in a web development context. Each example was then developed with complete unit tests in SimpleTest. After each example was working to my satisfaction, I would then decide how to show the code in the prose of the chapter. There were a couple of chapters which I basically rewrote from scratch after getting back comments from the tech review, and the results were much stronger chapters. I think the emphasis on testing; the use of both PHP4 and PHP5, and solid examples with UML customized to the examples and the patterns is going to position this book in a strong niche.

Speaking of php|t, all spare minutes are now devoted to polishing of my two presentations on “PHP5 Design Patterns” and “Test Driven Development in PHP”. If you are headed down to Cancun, look me up.

There was another request for code related to my previous book “PHP Graphics Handbook“. I have the code for the second half of the book in this zip file. As I mentioned in this previous post, if you still have access to the last code download, shoot me an email. If you know how to contact either of the other authors, I would be happy to know that as well.

   

SimpleTest 1.0!

Posted 2/26/2005 By Jason

Marcus Baker has released SimpleTest version 1.0! Download the files here and view the API documentation here. Congratulations Marcus, this is a fine work and an outstanding contribution to the PHP community.

For anyone who has not caught testing fever, try it out. There has been no other programming practice which has positively affected my programming practices the way unit testing and test driven development have.

I alluded to my in progress book in an earlier post. Each of the examples in the book was developed with unit testing coverage using SimpleTest, and all of these tests will be available in the source code download for the book. I hope the book shows good coding practices as well as demonstrating design patterns in PHP.