Professional PHP

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

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 | tek Wrapup
  • php|architect Test Pattern
Both comments and pings are currently closed.

12 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. 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

  7. 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

  8. 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.

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

    nice article, thanks to share

  10. Sean Brady says:
    12/7/2010 at 1:48 pm

    I found this article to be a very interesting read! Thank you for sharing this with us!

  11. Sandeep says:
    2/10/2011 at 6:14 pm

    Very Nice article, Thanks.

  12. eTek Studio says:
    5/26/2011 at 1:35 pm

    nice tutorial.. thanks for sharing

    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 (18)
    • Open Source (14)
    • PHP (99)
    • Software Design (29)
    • Usability (14)
    • Web Design (20)
  • Recent Comments

    • rsync to remote server via ssh  37
      Petr Halounek, Penni Tomasino, Rodney Kohnen [...]
    • WordPress BBCode Plugin  30
      wepniveth, Pamella Philipps, evakuat [...]
    • PEAR Templates  18
      Sang Bellotti, Kandice Sansing, car insurance estimates for teenagers [...]
    • Extreme Simplicity  15
      Gilbert Moatz, Roni Beauregard, Barb Geyer [...]
    • Manual Memory Management is Dead  6
      Grass Fed Filet Mignon, Kellie Carello, PAPANDOR [...]
    • Friendster wrapup: does MySQL scale  38
      Ollie Joya, nfl jersey on sale, selling scrap gold [...]
    • The Coding Apprentice  51
      fkawau, Annamae Mccane, Boca Raton Personal Injury [...]
    • The Legality of Republishing RSS Feeds  30
      dasfdsfsd, reebok authentic nfl jersey, Tory Rennemeyer [...]
    • Exceptional PHP  7
      Sports, The Click, Laraine Waterhouse [...]
    • PDO versus MDB2  42
      selling silver coins, Oliver Luongo, ddkoaorpa [...]
  • Recent Posts

    • Richard Thomas
    • 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
  • Site

    • Archives
    • Log in
  • Search