Pondering PHP

From Charlie.Huggardlee.Net

Jump to: navigation, search

Recently there has been an interesting discussion on Jim Wilson's Blog regarding the merits and demerits of PHP. I decided to write an entry with my personal thoughts on the matter. Namely that...


PHP is ok!


It's not the perfect tool all the time, but it's a good enough tool a lot of the time. Personally I've always viewed PHP as a server-side scripting language, and treated it as not much more than that. Like other scripting languages, many useful and even impressive things can be done with PHP, so long as those using the tool respect its limitations.

For example, if I need to setup a fairly good and flexible website quickly, I'll always use MediaWiki (a PHP project). As PHP runs nicely on and very often with Apache, MediaWiki will run on the vast majority of webservers already in existence (provided the presence of MySQL, which is often available as well), and this gives me rather well laid out no-mucking about site in a matter of minutes. Customizing and extending the functionality of MediaWiki itself has also proven to be easy thanks to decent documentation, and my ability to go back and read the actual code behind the MediaWiki engine.

In the past I've used PHP to make a quick and dirty authenticating proxy in less than 30 minutes. PHP can be used to throw up other quick yet usable prototypes of web components for complex systems. Even if these should be implemented robustly in another language later, it works for a quick demo or patch. (Ruby and Perl guys may argue the same about their languages, but it's all about comfort level and familiarity).

There's a few particular aspects about PHP that were brought up in the discussion which I would like to voice my personal opinions on as well.

Static Typing

As mentioned, PHP does not have a static typing system. Personally, I view static type systems as a safety net for myself, making sure I don't commit odd assignments affecting the rest of my code, and in large systems it can be a good thing (so long as you're not bypassing the static type system unnecessarily by casting everything to Object or similar other shenanigans).

With PHP, as previously mentioned I view it as a scripting language, I don't expect such robustness. Lacking a concrete static typing system permits more flexibility and increases the speed of writing scripts. However to write maintainable PHP code, the programmer should know the valid type or types of each variable at any given point in the script's execution and therefore is IMHO performing a basic static typing of the variables in the comments or at least her/his head. If you throw all forms of static typing to the wind there would be across situations where you would have to resort to manual type checks every time you needed to work with a variable.

Namespaces & Globals

As a scripting language, I don't really expect namespaces from PHP, but it would be nice if it were there. If you want to do extremely complex, robust, and reusable things with PHP, standard good coding practices help. Use functions whenever possible instead of globals, decide on a naming conventions for globals in your various components, et cetera.

I'll give the concessions that on the whole globals should often be avoided, and using classes for namespaces is a hack, but the language is very useful in spite of this.

In short...

It's my opinion that PHP makes for a handy and useful scripting language. While it may not always be useful for a particular purpose, it continues to be good enough to be used for solving many real world (especially web related) issues. As many have mentioned already, the key is to find the proper tool for the job, so don't criticize the stapler for not being a good enough welding torch.

--Charlie Huggard 23:12, 25 January 2008 (CST)


Name (required):

Website:

Comment:

To submit your comments, please solve the captcha.

or read what others have said

Facts about Pondering PHPRDF feed
Author Charlie Huggard  +
Post date 26 January 2008 05:12  +
Read more true  +
Web Search
Google
Personal tools