AntiPHPatterns, AntiPHPractices and How to Keep Your PHP Skills Sharp

Posted by · October 7, 2013 10:13 am

php-logoLast year, we recognized 25 folks as our Most Valuable Experts. Among them was PHP Wizard Ray_Paseur. In addition to having over 12 million points in PHP topic areas, Ray is the 8th ranked Expert overall on Experts Exchange. He’s written over 30 articles, almost all of which have received accolades from the community and Page Editors, including his most recent piece AntiPHPatterns and AntiPHPractices.

In the article, Ray discusses the phrase AntiPHPatterns, a term coined by Stefan Priebsch in 2010 to describe some of these high-level pseudo-solutions that appear in PHP. Stefan’s collection falls into four general categories: Constantitis, Globalomania, Singletonitis, and Godclass, each of which Ray touches on in his article. Ray also adds a collection of his own AntiPHP examples and shows how novice programmers often over-think or under-think specific problems.

We spoke with Ray earlier this week to talk about what inspired him to write the article, common mistakes PHP programmers make and how to avoid them and what advice he’d give to other article writers on Experts Exchange:

What inspired you to write the AntiPHPatterns and AntiPHPractices article?

PHP is an old language that has undergone a lot of changes over the years.  Unfortunately for people who are new to PHP today, there are a lot of very old and very bad examples published on the Internet, and these things tend to hang around forever.  For a novice, the bad examples are easier to find, because there are so many more of them!  PHP was originally intended to be the easiest programming language ever written, and in many ways it has achieved that goal.  But the environment is constantly changing, and PHP has had to change, too.  This article highlights some of the things that were (or are) screaming out for change, yet somehow still show up in newly-written PHP scripts.

How did you learn to program in PHP and how do you continue to keep your programming skills sharp?

I had some background in programming other languages, so I knew that the first place to go was the online documentation for PHP.  So I read the PHP.net web site — almost every page of it.  I also find that narrative and reference material is helpful.  I have eleven shelf-feet of books on PHP, and I’ve read them all, from the most basic to the very advanced, like Matt Zandstra’s excellent text.  I maintain a teaching library of code samples that solve the most common problems, and I periodically revisit the oldest samples to see if they are still useful, or if there is a better way to achieve the result.  It’s very enlightening to read a program you wrote a few years ago!

What are some common mistakes you see people make when programming in PHP and how can people avoid them?

Probably the most common mistake is assuming that a code sample is a wise choice because you found it on the internet!  Everything on the internet is true, according to Ben Franklin.  But at a more serious level, the biggest and most frequent mistake is assuming that you can write PHP programming without any structured learning of the PHP language.  Trying to do that is like trying to learn to bake by looking at an apple pie.  You may be able to appreciate the end-product, but looking at the pie can tell you nothing of the process.  The same is true of looking at computer code.  Any novice programmer can advance her skills by leaps and bounds with a month invested in studying a good PHP book.  To advance by trial and error would take years.  And if you don’t know good code from bad code, you will lose even more time in the trial and error process.  Right on the home page of PHP.net there is a link to the introductory tutorial, but it often gets overlooked and that’s a shame.

Why do you write articles on Experts Exchange?

After a couple of years of teaching PHP for the Boston University Center for Digital Imaging Arts, I have found the same PHP-related questions coming up over and over – both among my university students and at EE.  Everyone who starts thinking about building a web site has some of the same questions, and when I can consolidate my thinking adequately to reduce the questions to writing, I create an article.  It makes for easier and more comprehensive ways to respond to the more common questions.  And it provides me with a teaching example that I can share at EE and use in the classroom.

What are some tips you might have for people writing their first article on Experts Exchange?

Find a common problem you understand well and create a few different demonstrations of the solutions.  Compare the solutions and see what works well and what does not.  Then make a quick outline that leads the reader from understanding the problem to seeing the different solutions.  Once you have the outline, the narrative and examples will be easy to add.  If you include program code, test it to be sure that it works!  And use the principles of the Short, Self-Contained, Correct (Compilable) Example (SSCCE) to make any demonstrations succinct.  Good proofreading helps, and the article editors will help you, so don’t be overly concerned about writing style.  I’ve never written an article that did not represent a collaboration between my own work and the ideas of the editors.