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
You can leave a response, or trackback from your own site.

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

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

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

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

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

    nice article, thanks to share

  13. Nick says:
    10/11/2010 at 12:05 pm

    you’re one smart cookie. thanks for posting the slides for those of us that couldnt attend

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

  15. Montreal Web Design says:
    1/8/2011 at 7:48 pm

    You prepared really good slide deck, it can be of great use for software engineers.

    p.s another option would be to remove the dependency altogether and use AOP.

  16. WebCorsa says:
    2/8/2011 at 4:53 am

    Simply desire to say your slide deck is as astonishing. Thank you for sharing this with us!

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

    Very Nice article, Thanks.

  18. dravn says:
    2/16/2011 at 10:48 am

    An interesting blog that easily loses me in moments – I’ll be honest and say I came with motives. I hoped you might like looking at this link, where I’ve blogged about a new social networking site that would be amazing to see made. If it ever got made, I wouldn’t be greedy – only hoping 5% if possible for coming up with the idea. So far, everyone loves the idea on the blog so I’m posting this message to a few blogs to generate interest.

    TrendE

    http://dravenames.blogspot.com/2011/02/trende-new-social-networks.html

  19. web development service says:
    2/24/2011 at 9:27 pm

    hi this is good.

  20. palatine says:
    2/28/2011 at 9:39 am

    Great tutorial. thankyou

  21. college classifieds pro says:
    3/5/2011 at 9:32 am

    This last year our team did just want you recommended for our website, re-organized for change. Our PHP/Javascript/mySQL website was very hard for new developers to work with. There was a lot of code redundancy, so we decided to restructure the website by using more classes and stripping out all SQL calls from within the code. While this effort took almost 9months, it was well worth it! thanks

  22. uzamax says:
    3/6/2011 at 10:36 am

    %100 Do?al ve hiç bir yan etkisi olmayan Uzamax’? ke?fedin
    UZAMAX içeri?inde mineral ve vitaminler bar?nd?ran, do?al bitkielerden üretilmi? g?da deste?idir. ?çeri?inde herhangi bir kimyasal ürün bulunmamakla birlikte tamamen do?al kurutulmu? bitkisel bir kar???md?r. Sadece birkaç ayl?k kullan?m kürü sonras?nda bile uzamax’?n etkisini hissedeceksiniz.

    Uzamax kullanarak do?al yollarla bünyenize gerekli olan tüm besin, vitamin ve mineralleri vücudunuza alman?z? sa?lar.izlanda yosun hapi

  23. Web Design says:
    3/28/2011 at 10:48 pm

    Great tutorial. Well done!

  24. Palatine says:
    3/30/2011 at 2:12 am

    Great tutorial. loved the slides thanks for sharing.

  25. Ales says:
    4/19/2011 at 1:45 pm

    Thank you. Just what I was looking for. Great tutorial. Ales

  26. kevinxiaoer says:
    4/20/2011 at 5:29 pm

    i just catch the problem. and now i will can fix it. thanks

  27. vuitton bags says:
    5/6/2011 at 12:59 am

    I’m sorry to say there may be a louis vuitton tote bag lie in your closet.And now run to see whether there is a woven label say it’s made in US?Coach,mostly we can say it as a fashion icon,but can’t regard as costless goods.During the worse economic crisis ages,louis vuitton tote CEO Lew Frankfort had a new definition as a young silk-stocking brand “You can own it easily”.We can’t deny the saying run it’s degree up.Let’s take a Lv as an example which you can buy it at around 6000 RMB while a louis vuitton mens wallet tote only deserve one third of it.Though you see all louis vuitton tote selling shops or flagship malls close to LV but it still can’t play as it was that degree.Just like we all know that neighbours have different degrees too.Thanks for the high duties ,discount louis vuitton bags tote becomes valuable brand,but we still confuse a 5000 RMB bag has a what percentage for government?

  28. Abdul says:
    5/6/2011 at 11:02 pm

    I agree to this post. Since My Blog shows following:

    Rasmus Lerdorf (born on 22th Nov 1968, in Greenland) is a Danish programmer with Canadian citizenship and is most notable as the creator of the PHP programming language.He authored the first two versions. Lerdorf also participated in the development of later versions of PHP led by a group of developers including Jim Winstead (who later created blo.gs), Stig Bakken, Shane Caraveo, Andi Gutmans and Zeev Suraski.

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

    nice tutorial.. thanks for sharing

  30. php web development from india says:
    6/15/2011 at 3:36 am

    Our PHP/Javascript/mySQL website was very hard for new developers to work with. There was a lot of code redundancy, so we decided to restructure the website by using more classes and stripping out all SQL calls from within the code. While this effort took almost 9months, it was well worth it! thanks

  31. ralph lauren says:
    7/26/2011 at 8:17 pm

    nach verschiedene Kunststil und Thema. Außerdem können wir auch nach Maß schaffen, die für unsere true religion Kunden die Einzigartigkeit Ihrer Individualität betonen.
    Ölgemälde
    Ölbilder

  32. casque monster says:
    7/26/2011 at 8:18 pm

    Mit Tiffany Schmuck wie z.B Tiffany&Co und Anhänger sieht man ziemlich elegant und charakterisiert aus. Gönnen Sie sich Glaskunst von Tiffany mit günstigen Preisen in Tiffany Onlineshop.
    Tiffany & co
    Tiffany Schmuck

  33. Jones kent says:
    9/12/2011 at 3:56 am

    THanks for sharing.Will wait for your next blog.
    epixeltechnologies.com/

  34. Heat Pump Installers Auckland says:
    9/27/2011 at 9:28 am

    Everything you mentioned is correct, but there are so much upsides. Like, able’t be fired.

  35. Double Ended Baths says:
    11/4/2011 at 7:51 am

    I have been using codigniter for the last 3 years. Maintainable code is an area that I’m researching in at the moment . I found your post very informative and resourceful.. thank you very much

  36. Yagnaum says:
    11/10/2011 at 1:39 am

    http://www.Yagnaum.com – the leading software development company providing custom application Development services using PHP, .Net, Drupal, Microsoft, ATG, etc.

    Follow Yagnaum systems at LinkedIn @ http://www.linkedin.com/company/yagnaum

  37. Acheter Nike Air Max says:
    11/14/2011 at 1:53 am

    dédouanement. Bon de réduction peut être eu avec ces magasins si vous êtes disposé à régler pour les gants

  38. Chaussre Air Jordan says:
    11/14/2011 at 1:54 am

    vue de face montrant sur un fond blanc. Le visage doit être comprise entre 1 et 1 3 / 8 pouces à partir du menton au sommet de la tête. Chapeaux, coiffures et uniformes, sauf mot de vêtements religieux quotidiens ne peuvent pas être portés.

  39. sunita says:
    11/28/2011 at 10:15 am

    Nice tutorial thanks for share.

    PHP Tutorial

  40. breitling aeromarine super avenger says:
    12/20/2011 at 8:23 am

    Rolex Datejust Two Tone

  41. Hassan Basaldua says:
    12/27/2011 at 4:16 am

    Thanks a lot for your interesting article. I have been searching for such information for a very long time. Not everything is completely easy to understand to me, but it is definitely interesting and worth reading.

  42. Rockberries Invest says:
    12/28/2011 at 3:22 pm

    Breaking News: Rock Plc Berries Lang & Schwarz sees fair value such shares at € 46.98! Dear investor, dear investor, We will contact you between middle midst of the holiday season or still hammer at you. In today’s breaking news to rock Berries Plc (A1JNYV) are our a using the brilliant results of a company’s current assessment of the prestigious brokerage firm Lang & Schwarz . We would like to take this place , Member an investor event of Berries Rock Plc, which there are the consisting distributed presentation materials has made ??available. First of all: Lang & Schwarz comes to the conclusion Summary , that is for Rock Berries a fair value of € 46.98 each must share. At a current share price of 19.60 € results from this fundamental undervaluation thus thus a short-term upside potential of at least at least 139 percent. But the Opinion displays moreover that in this place or much more to imagine schaffbar.

  43. Wava Rogalski says:
    1/10/2012 at 5:14 am

    Your Buzzness,
    My boyhood actually preceeded the Nixon administration, so I guess I outrank you. Hey gang, Geezer Wars! I am neither surprised at your insult, as that’s exactly how you entered the fray. However, instead of wasting valuable electrons insulting me, why don’t you summarize what you learned in Statistical mechanics class O Great One? The important stuff, like how chaos naturally crystallizes and evolves into organic entities and processes with primary, secondary, tertiary, quaternary, and as yet unidiscovered levels of structure and interaction, as in the greater than 10,000 complex enzymes operating within a geologically ancient unicell, the absence of any one of which renders the unicell lifeless or dysfunctionally short-lived or sterile. Not even bringing in the organelles and DNA/RNA programming and its support and executive systems that contain the potentiation for common life processes, wings and trunks and teeth (two sets!) and dreams. Oops, that would have been in your Org Chem, Bio Chem or Microbiology course prerequisites for the rest of life.

  44. martinkaden says:
    1/18/2012 at 3:02 am

    Nice explaining about PHP.I have been searching for such information on PHP thanks a lot

  45. sigma solve says:
    2/6/2012 at 3:30 am

    Our PHP/Javascript/mySQL website was very hard for new php developers to work with. There was a lot of code redundancy, so we decided to restructure the website by using more classes and stripping out all SQL calls from within the code
    because i am the php developer . from usa

  46. Outrank Smart is a new kind of backlink generator that provides the user with the ability to get backlinks from link exchanges on autopilot. The system gets thousands of links with the push of a button says:
    2/8/2012 at 6:14 am

    Outrank Smart is a new kind of backlink generator that provides the user with the ability to get backlinks from link exchanges on autopilot. The system gets thousands of links with the push of a button…

    [...]ZendCon: Writing Maintainable PHP Code – Professional PHP[...]…

  47. adapter says:
    2/15/2012 at 7:16 pm

    ggggggggggggggggggggggg

  48. blacknester says:
    3/11/2012 at 2:03 pm

    Great blog and it has helped me a lot to organize my website, http://cliplist.com, all my pages before it were a mess and almost impossible to maintain.

  49. Palmer Juste says:
    3/20/2012 at 7:47 am

    Wow, superb weblog structure! How lengthy have you been blogging for? you make running a blog look easy. The total glance of your site is excellent, let alone the content material! Prime Escorts, 350 Kennington Lane, London SE11 5HY, 028 8788 0034

  50. seo, backlinks building says:
    5/12/2012 at 9:04 pm

    Fantastic blog post, saw on…

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

    • The Legality of Republishing RSS Feeds  28
      Tory Rennemeyer, eenicker, Reverse Phone Lookup [...]
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)  258
      Tuan Lal, Lavagem de estofados, Edward L. Kind [...]
    • php | tek 2008  36
      how to mend ice machine, Akademija Debelih, Odbacena [...]
    • goto in PHP  59
      kasor, Thomas Valdivieso, Murray Ziadie [...]
    • Firefox Extensions for Web Developers  33
      kasor, Website Design Toronto, mobila bistrita [...]
    • Why PHP is easier to learn than Java  68
      kasor, Justina Calvery, Guy Lipton [...]
    • Meta Tag Refresh Faux Paux  43
      html email templates, E-Juice Reviews, image [...]
    • Improved Error Messages in PHP 5  49
      Carroll Tina, Przeprowadzka, Emery Harari [...]
    • Benchmarking PHP's Magic Methods  33
      kayu oyunlar?,dora,oyun,oyna, Benjamin Bejjani, paypal website [...]
    • Microbenchmarks of single and double qouting.  24
      kefir grains minneapolis, sexshop dildo, tuim688 [...]
  • 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