Prusak.com

Serving up my thoughts since 2004

PHP – A Programmer’s Perspective

This article will hopefully give you a better understanding of PHP, and how we get here in the first place.

Too many people know PHP without really understanding what’s going on under the hood.
The big picture as well as the small details. Not just the “how” but also the “why” and the “why not”.

First, I’d like to give you a better understanding of why I’m writing this article and how we got here in the first place. Afterwards I’ll help you get a better understanding of PHP.

I’ve been doing web development (mostly back-end) since 1995 (I actually introduced Zeev Suraski to PHP). I’ve been involved in projects ranging from complex sites with millions of page views a day, to helping kids write their first PHP script. Recently I’ve changed tracks, from mostly development, to teaching PHP. The title on my business card now reads “PHP Educator”. I was a technical instructor for 2 years in the army so this comes as second nature to me.

As part of my new role I have been exposed to a lot of people who want to learn PHP. In addition, I have become more aware of existing learning materials and other resources for people who want to learn PHP. This includes the PHP manual at php.net, various php “how to” web sites, articles, books, mailing lists, users groups, etc.

While many of the ideas in this article have been in my head for quite a while, it wasn’t until I started teaching that I connected the two main ideas I’d like to write about:

  1. There are two very different types of PHP programmers.
  2. Many of the “Learn PHP” articles online are evil.

After explaining why the two different types of PHP programmers are different, it should become obvious why most online articles are evil.

In many ways PHP has changed the landscape for computer programming. It has certainly lowered the entry barrier to programming:

  • It can be embedded into an HTML document.
  • It has a very easy learning curve: most people can start writing their own scripts within a couple of hours.
  • Most Unix-based web-hosting packages include PHP support, more than any other programming language.1
  • It has given the public a whole new motivation to write computer programs: anyone who is involved in creating web pages and wants dynamic content can easily do it.
  • You can even download it to your PC or Mac and run it locally.
  • All of this comes without a hefty pricetag; PHP is free!

I’ll be the first to say I am very glad that PHP has opened up the door to programming to so many people. Unfortunately, some issues have arisen because of the way most people learn PHP.

PHP was written from the ground up to solve a specific task – creating dynamic Web pages. In many ways, this makes PHP different from most other programming languages. In order to be exposed to most other programming languages, you would probably be a programmer, an aspiring programmer, or someone who is heavily into computers. For these people, programming is the “end”, not the “means”.

I know I got into programming this way. I learned programming because it was fun. There wasn’t a specific task I needed to accomplish. I just enjoyed it. Later, I got my Bachelor’s Degree in Computer Science.

On the other hand, many of the people who are exposed to and want to learn PHP, don’t really want to be programmers per se. They just want to create dynamic web sites. PHP is the means, not the end.

So, let’s say you’re cool with HTML, CSS, maybe even some JavaScript and you’ve decided to take the plunge and learn PHP. Since you’re already very familiar with web and you probably learned HTML from the web (online tutorials and view->source) then why not do the same with PHP?

There is the php.net online documentation as well as plenty of online tutorial sites, and all of this information is FREE. You can read a few introduction tutorials, a few How-To articles and voila – you’ve just written your first guestbook in PHP.

The problem is that you’ve been learning how to use PHP to solve specific problems and not computer programming in general. These tutorials have been feeding you fish, but no one is teaching you how to fish for yourself.
All of this brings us back to why there are two different types of PHP programmers.

I think there are two main groups that most PHP programmers fall into.

1 – People who write computer programs for their day job. Most of these people either have some formal education in computer science, or have been programming for a while and are self taught and know the fundamentals of computer science.
For simplicity’s sake, I’ll call these people programmers.

2 – People whose day job involves the web or computers but their title is not “programmer”. These are usually web designers2, system administrators, PC technicians, etc. For them, PHP is something that can add value to their work, but is not their direct responsibility.
For simplicity’s sake, I’ll call these people “designers”.

The designers are very different from the programmers.. They lack a proper foundation of computer science fundamentals. The problem is that they don’t know what they’re missing. In other words, “they don’t know what they don’t know”.

This brings us to why many of the “Learn PHP” articles online are evil.

They’re written by the designers. Of course they mean well, but the articles often explain a specific solution to a specific problem. They usually teach by example, going into detail with the “how” but not the “why”. These people had a specific problem and were able to solve it with a specific solution. It works even if it’s not the “right” solution.

If all you know how to use is a hammer, everything looks like a nail.

Before I continue, I’d like to point out that in many cases, it doesn’t matter.
If you’re writing an intranet application that allows company employees to choose what they want for dinner, who cares how it’s written. If it works – it works. Period.

Unfortunately, the “if it works – it works” concept has crept into the professional realm as well. This is one of the biggest problems a company has when trying to evaluate programmers. You can’t “see” a computer program in the same way you can see a building or a piece of furniture.

Sure you can view the source, but that means nothing to non-programmers. All the client really cares about is if it works, not how it works. This means that your code could be:

  • Insecure (easy to break into)
  • Inefficient (gets really slow with large data sets)
  • Non-scalable (won’t work for more than 100 users)
  • Unmaintainable (difficult to understand and modify)

But it works.

For those of you who want to write applications that don’t just work, first you must understand how to write good software in general. My goal is to help you understand.

In my next article, I’ll help you understand the three pillars that hold up any great PHP programmer.

As always, comments are very much appreciated.

Ophir

Footnotes:

1. OK, I don’t have the facts to back-up the “more than any other language” but please send me data either proving or disproving this.


2. By Web designers I do not mean people who create a PSD in photoshop and hand it over to the “tech guy”. I am referring to people who’s primary concern is the front end and are fluent in PC or Mac usage. They are experts in all aspects of web related “front end” technologies. This includes HTML, CSS, DHTML and some JavaScript. They understand the pros and cons of using a gif vs a jpeg (or png) image. They understand how page caching and cookies work.

6 Comments

  1. I agree with you. I used to teach an afterschool class in general computing. PHP is a great vehicle for teaching the fundamentals of programming, but the teacher must be careful to teach programming, not PHP. I find, it’s often beneficial to look at more than one programming language when teaching programming concepts. I like languages with similar syntax (C, C++, Java, Javascript, PHP) because you don’t have to spend much time explaining the language. It seems to help, when demonstrating different concepts to show them in more than one language, even if the students are only going to work with one language. I find, it seems to help separate concept from application.

  2. I agree with you by and large, but there is just one point where I’m a little confused. Why do you put administrators in with designers? These are two totally different animals.

    ophir: I’ve added footnote #2 to address this question.

  3. Well said. I agree with you entirely and have often had the same thought myself. I rarely read PHP articles (and almost skipped over yours) because I am so used to seeing articles with a million (often poorly written) detailed lines of code to solve a specific problem in a specific fashion. And, when I say specfic problem, I don’t mean anything interesting like… Object Persistence, or, scalable file-upload solutions. I mean things like, guestbooks, email forms, and blogging engines.

    I look forward to reading your next article.

  4. hello.Thanks for your good article!

  5. Whoa, about time I see a good article like this. Congrats.
    I agree completely in the definitions you give (truly, where are administrators?), and I’ve had many good experiences using PHP to solve computer science specific problems, like building a compiler, genetic algorithms, design patterns. Things like Object-relational mapping, workflow engines and business rules engines are hard to do in PHP (compared with Java for instance), but you can make them if you have in mind the quirks of PHP, being stateless, script language and such.

    I only wish that someday, PHP could become a full fledged platform for standalone applications but keeping the web specific parts as easy as it is now.

  6. Actually, there is a product out there that will compile PHP scripts into windows executables. I’ve never tested it, but it’s out there. Or, you could ship some scripts with the php executable and a batch file for putting it all together. Your code would be all exposed that way, but that’s not always a problem.

    Or, on *nix/OSX, you can just include a bit of shell scripting at the top of your php doc and list php as a dependancy. I run PHP scripts on lots of machines that don’t even have web servers installed.

    None of this is as ideal as a real, crossplatform, PHP compiler, but we may get there someday. Until the, you can make it work if you’re willing to get creative.

Leave a Reply

Your email address will not be published.

*

© 2024 Prusak.com

Theme by Anders NorenUp ↑