IDE(s): TextWrangler plus MAMP
(From the homepage for the PHP Group)
|“PHP is a popular general-purpose scripting language that is especially suited to web development.
Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.”
PHP is a very popular programming language and runs on over 200 million Web sites, including some very large ones like Facebook. Not bad considering PHP was not originally conceived as a programming language.
According to creator Rasmus Lerdorf in a 2012 interview with the IEEE house magazine Computer, PHP was originally just a collection of utilities he hacked together to make his web page development easier. He found he was writing the same code over and over again for his clients so like any good coder he took it upon himself to automate the process.
All well and good.
But other programmers saw what he was doing and asked for copies of Lerdorf’s toolkit. Hackers being who they are, when they found bugs they fixed them and passed the changes back. Eventually he handed off responsibility for pieces of his code to others and PHP grew in scope. Each programmer added functionality to scratch their own particular itch and contributed their code back to the community. Lerdorf mostly stayed out of any code architecture decisions, preferring to leave that to the community.
Those of you who are familiar with the open source development process may see the fundamental flaw here.
For the rest of you, let me explain. When you set out to create a programming language (or any non-trivial software project), you create a specification. This is a document that sets out the conventions that everyone has to follow in order to participate. For example, you make a list of keywords, words that have special meaning in the language. This lets others know that these words can’t be used for anything else.
With a specification document, you can have many developers working on the project and have some assurance that they won’t be stepping on each others toes.
A specification document can and does get updated but it’s usually in a way that adds features or project scope without significantly changing the basic rules.
Next, even an open source project staffed by volunteers needs someone who is the final word on changes. This could be an individual (like Linus Torvalds with Linux) or a group (like the team that manages Debian).
Without these, the software project has no real structure. Features get added and taken away without much of an explanation and some functionality may be either missing or duplicated by multiple redundant methods.
The fact that PHP is so widely used and seemingly robust is more of a testament to the heroic efforts of the community of PHP developers who are applying spit and baling wire to make this code work.
But there are always consequences.
Just for fun, I searched for ‘php sucks’ and got almost 10,000 hits. After glancing through the links, here are some of the most common complaints:
- The code libraries are a disorganized mess
- Unnecessary duplication of functionality
- No coherent design
- Messy and complex
- Incorrect or incomplete documentation
- Data input needlessly complex or error-prone
- Poor code readability
These are some of the milder complaints. There are more, but you need to be a programmer to fully appreciate the horror.
I don’t blame Lerdorf. By his own admission, PHP was never meant to be a programming language. It was just a bunch of neat, useful hacks that a talented, enthusiastic community of programmers adopted as their own. In a sense, the story of PHP is a pure expression of the Hacker Ethic.
NOTE: This is not a PHP hit piece. As I’ve said, I’m not a professional programmer, just an interested bystander. I have no dog in this fight. I just have an incurable compulsion to lend perspective.
First off, we need to install PHP. This is pretty easy. You can either use one of the pre-built installers or just build it from scratch. Mac OS X comes with free programming tools as an optional install so I already have PHP on my system.
In theory you can use PHP like any other scripting language, but since it’s designed for Web development you really need to set up a Web server that understands how to run PHP code. Fortunately some very smart people set up a software stack called LAMP (Linux-Apache-MySQL-PHP) as a free, turnkey solution for Web development. LAMP started out on Linux but variants are also available for other platforms, such as MAMP for Mac OS X or XAMMP for Windows. What they all have in common is easy installation and setup. I’ll be coding on my MacBook so I’ll be using MAMP.
Now I just need a text editor so TextWrangler it is. I could use something fancier like Aptana, NetBeans or Coda but I don’t plan on coding up anything terribly complex.
Since I’m not looking to do anything fancy, I created a simple form. The user is asked to input a number between 1 and 10 and press Submit.
Then the number gets passed to another page, where a simple loop prints “Hello World!” based on the number entered by the user.
I felt this was an appropriate spin on the standard “Hello World!” program as PHP was originally designed to manage HTML forms.