Professional PHP

PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.
« Looking Towards the Cloud

ZendCon: Writing Maintainable PHP Code

October 19th, 2009

I’ve finally made it to my first Zendcon. Its nice to see some familiar faces and also nice to put new faces to familiar names.

I gave my maintainable PHP talk this morning. I love doing this talk. Thanks to everyone who attended. I’ve put the slides (pdf) up on my talks page.

Much of the material is based on Test Pattern columns that I’ve written for php|architect. Here are some of the specific columns.

Organizing For Change
This is where I developed the outline for the talk
Dependency Injection
This is a more in depth discussion of code reuse and dependency injection
Modeling Dependencies
This is where I talk about coupling, layered design and abstraction
A Closer Look at Cohesion
This is where I developed my explanations of cohesion and the single responsibility principle
Searching the Code
Good designs are searchable

One thing I like about both writing on and presenting on the same material is that I get feedback from the presentations that I can put back into the writing and vise versa. I’m looking forward to finding some better ways to explain layering and the depend on abstractions principle. If you saw the talk, was there anything you particularly liked or needed work? Leave a comment here or on the joined.in page.

Here are some of the books I mentioned in the talk.

PHP in Action: Objects, Design, Agility
This is a really good next step if you’re interested in maintainable code, testing, and object oriented design.
Refactoring: Improving the Design of Existing Code
This is the classic treatment of Refactoring. Probably everyone considering themselves a professional programmer should read this. The examples are in Java, though.
Working Effectively with Legacy Code
This is a good book if you want to start testing and refactoring in a large system that doesn’t currently have tests. Again, the examples are in Java.

I sat in on the PHP Code Review talk this afternoon. I thought it was a great complement to my talk. I tend to be a bit theoretical and this talk was very practical, but we covered a lot of the same principles. Nice talk. Nice scheduling, Zend.

I’m really looking forward to tomorrow. Unfortunately, I have to go back to work on Wednesday.

Filed Under

  • PHP

Related Posts

  • php|tek Slides
  • programming has warped my mind
  • Why is PHP Code Considered Hard to Maintain?
  • php|architect Test Pattern
  • Writing an XPath expression evaluator
You can leave a response, or trackback from your own site.

21 Responses to “ZendCon: Writing Maintainable PHP Code”

  1. Stephan Hochdoerfer says:
    10/20/2009 at 12:28 am

    I have to disagree with your list of drawbacks of DI. You mention that DI requires all potential dependencies to be instantiated. I do not see a drawback here, in case you hardcode the dependencies inside your classes you will also need instances of the objects that the class relies on. Optional dependencies can be set via Setter-Injection, thus not every dependency needs to be passed as constructor parameter. Many direct dependencies can force you to pass many parameters to the constructor but in such a case your application design might not be the best.

  2. artur ejsmont says:
    10/20/2009 at 7:37 am

    Very nice slides, i liked it.

    Stephan, did author not mean that dependency has to be instantinated locally or become dependency?

    I agree it can become an issue as you want to use an object and suddenly you depend on everything it depends on. Then you have to pass these instances in or create them in many many places.

    Usually list of dependencies is not that long but it can be still a pain to pass the along everywhere you go. Especially that they add up int a

    Lets assume my validator depends on the config (does not matter why or if it makes sense). Now every form using it will need to inject config object. So every controller using forms like that one has to pass config as well etc. Or every form has to create new instance which makes it directly depending on config (even worse i guess).

    Optionally for shared instances some people use repository like Zend but i dislike global-ness of that approach a bit. You never know who add stuff to it and when or where. But for some very basic instances it might be the only easy way out.

    Art

  3. Jeff Moore says:
    10/20/2009 at 7:52 am

    There are situations where DI and lazy loading conflict. You can do setter injection to inject optional dependencies. that may also force you to move logic outside of the class to make that decision to inject where you’d rather have that decision inside the class.

  4. Stephan Hochdoerfer says:
    10/20/2009 at 2:44 pm

    Managing the dependencies and building the objects should be done by your DI container so you do not need to worry about deeply nested objects. Instead you just have to ask the container for the object you want, all the wiring is done automatically for you.

  5. abc says:
    1/28/2010 at 11:33 pm

    did author not mean that dependency has to be instantinated locally or become dependency?

  6. Arif says:
    2/12/2010 at 2:01 am

    Nice tutorial.Thank’s

  7. nicopico says:
    2/16/2010 at 5:08 am

    important issue, nice post.

  8. IT Ninja says:
    2/26/2010 at 9:41 pm

    btw, the National Security Agency was recently hacked. Yes hacked! But it was downplayed to the media for obvious shameful reasons. Here’s the link :

    http://pinoysecurity.blogspot.com/2010/02/wwwnsagov-hacked.html

  9. purencool says:
    3/28/2010 at 1:23 pm

    Thanks for the slides really enjoyed them. I have one question as I did not see the talk. Why do you turn an array of variables into an object/s

  10. Ranjan says:
    5/12/2010 at 4:49 am

    hello,
    I seen your PHP Talks, it nice explaining about PHP.It really impotent think in PHP.
    thanks

  11. Ruchi says:
    5/12/2010 at 4:52 am

    wow,
    you delivers a very nice slide, I really love it.
    good work keep going on.

  12. kevin says:
    5/21/2010 at 7:45 pm

    Just want to say what a great blog you got here!
    I’ve been around for quite a lot of time.

  13. Jonemac says:
    5/30/2010 at 11:05 am

    Yes,your are the best php protor. Keeping learn php from you.

  14. PHP developer says:
    6/14/2010 at 12:00 am

    Hi, i had read you article about PHP development, its really good. i am looking for more articles related php development and how to develop a website from you…keep posting nice articles…..

  15. Corwin Jensen says:
    6/15/2010 at 10:04 am

    I have to disagree with your list of drawbacks of DI. You mention that DI requires all potential dependencies to be instantiated. I do not see a drawback here, in case you hardcode the dependencies inside your classes you will also need instances of the objects that the class relies on. Optional dependencies can be set via Setter-Injection, thus not every dependency needs to be passed as constructor parameter. Many direct dependencies can force you to pass many parameters to the constructor but in such a case your application design might not be the best.
    +1

  16. jessica says:
    6/23/2010 at 7:43 pm

    Php is very important, and want to study, but may be very difficult.

  17. voiper says:
    6/23/2010 at 9:46 pm

    ???????????

  18. ?? says:
    6/23/2010 at 10:06 pm

    ??????????????????

  19. Dania Anwar says:
    7/8/2010 at 10:46 pm

    may be we can help you out. our company is an expert in web content writing and management system. you can keep in touch through email service. we have alot more to offer
    should you need any further assistance we will be happy to provide you with details.
    we have packages that you might be interested in. mail me if u want to know more. :)
    seeking forward to hear from you

  20. Yasir says:
    7/15/2010 at 5:22 am

    nice article, thanks to share

  21. ZendCon: Writing Maintainable PHP Code | PHP SPain Blog says:
    7/23/2010 at 1:18 pm

    [...] Continue reading/Seguir leyendo This entry was posted in Programming and tagged php. Bookmark the permalink. ← Sarah Snow Stever Easy “Maintenance Mode” with PHP → [...]

Leave a Reply

Click here to cancel reply.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

code: use [code=php][/code].

Comment Preview

    Subscribe Feed
    Share Subscribe to this blog…
    Share Bookmark or share this page…
  • About

    My name is Jeff Moore. I'm a PHP programmer living in San Francico and working for a startup.

    More about me…

  • Categories (Home)

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

    • Programming Language Trends via Google  19
      Craigslist pva, jessica, Scott [...]
    • Looking Towards the Cloud  35
      bentonville multiple listing, cosmetic dental, Sam Brodish [...]
    • PHP versus ASP  8
      Marhta Blight, Ravi, Ryan Brooks [...]
    • How to Transfer Mac OS X Application Data between Computers  59
      Website Migration, harry the computer support guy, Dotty Salvage [...]
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)  157
      lehuuphuc, Robert Parthemer, Lingerie Intimate [...]
    • PHP Games  25
      jessica, Tennille Cranor at Chilli Plants, Lucas Ortell [...]
    • un-PEAR-ing  5
      jessica, Eugene Panin, Arnaud [...]
    • The Legality of Republishing RSS Feeds  23
      kevinxiao, Marissa Miscovich, Quick Student Loans [...]
    • Faster Page Loading  4
      jessica, angular cheilitis, Aaron Rosenfeld [...]
    • PDO versus MDB2  15
      jessica, kevinxiao, Gavin [...]
  • Recent Posts

    • ZendCon: Writing Maintainable PHP Code
    • Looking Towards the Cloud
    • Holiday Tech Support
    • Closures are coming to PHP
    • php | tek Wrapup
    • php | tek 2008
    • Sarah Snow Stever
    • Benchmarking PHP’s Magic Methods
    • The Endpoints of the Scale of Stupidity on Video
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)
  • Site

    • Archives
    • Log in
  • Search