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.

5 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?

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

    • A Glimpse into the Future: PHP 6  5
      Vede?evanje, php6, [...]
    • Improved Error Messages in PHP 5  31
      css, Amsterdam, amoxicillin-overdose [...]
    • Ruby versus PHP or There and Back Again  9
      Amsterdam, Hari K T, Stuart [...]
    • Google Hosting  16
      Eugenio Havens, commercial factoring, Sokol [...]
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)  137
      tony, omar, Vlatro [...]
    • PDO versus MDB2  12
      stot, Dapra, Jeff [...]
    • How to Transfer Mac OS X Application Data between Computers  48
      Paint Bull, bru, Tom Doran [...]
    • ZendCon: Writing Maintainable PHP Code  5
      abc, Stephan Hochdoerfer, Jeff Moore [...]
    • php | tek 2008  6
      Jane, Bill, Deepak [...]
    • goto in PHP  48
      drborsos, Frank Munch, Oliver [...]
  • 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