Question

In response to this question, I'm sure many people would object that PHP isn't the best choice for desktop programming, and would recommend something like Ruby or Python instead. I thought it would be interesting to have a discussion on why.

Aside from arguments about whether PHP is a good language overall, what are your criteria for a good desktop programming language (as opposed to web development)?

Was it helpful?

Solution

You say "Aside from arguments about whether PHP is a good language overall" -- but I think that is the crux of the issue. PHP became popular as a web development language because it integrates well with an existing stack of web tools (inline HTML, good Apache integration, built-in MySQL support, etc) -- not because it is well-designed language that is easy to work in. (It's not, by the way.)

If you take the web away and use PHP for desktop development, what do you have left? A weakly typed, inconsistently-featured language with no support for desktop UIs and a horrific mess of a standard library. People don't use PHP that way because it just doesn't make sense.

OTHER TIPS

PHP is designed specifically to create web applications. While it is technically possible to create desktop apps using it, you're really sanding off the corners to fit the square peg in the round hole.

There are so many programming languages designed with the desktop as a target, it just doesn't make sense to try and shoehorn PHP in to a world it's not meant for.

For perspective: PHP is my job

PHP for desktop applications:

The ease of distribution from a desktop application with the performance of a web application.

This sounds like a trite answer, but I think the reason most people don't use PHP as a desktop programming language is because people don't use PHP as a desktop programming language.

Meaning, there isn't a very strong community around GUI desktop applications using PHP - this will impact the tools a developer will have available, the resources he can go to for help, and for a company or commercial endeavour, the additional programmers that will have the skillsets necessary to work with a very niche set of tools.

Does $language_under_consideration do the job I want easier than $other_language?

E.g., I've found php interfaces to mysql to be great for quickie DB work. I'd not want to write php for a GUI app on Windows though....

Because it is catered entirely toward web programming, and while it may have the necessary tools for desktop programming there are other languages which are much more capable, more efficient for the job.

Personally I don't like a lot of the language principles so I only use it when I'm forced to.

Is it installed by default on the target platform? Because if it is not, then there is more friction to adoption.

I'm surprised nobody has said this. As a web developer, I only use PHP because that's what the clients usually ask for. They want to deploy on any hosting they can find and all web hosting share one common denominator: PHP. Also, we do a lot of rescue mission style coding where we have to fix sites already written in PHP. As an honest developer can't recommend PHP as a platform in good conscience for serious web development. I would never choose PHP for any project, web or desktop. Python is pretty great for desktop apps. It's more dynamic than PHP, more sane, and more productive.

  1. If you are making a GUI app, PHP is not very suitable. Consider (1).NET/Mono or (2) Python with PySide (QT). See below.
  2. If you are making a large back-end enterprise app, PHP is not suitable. You need a structured language like C# or Java which is more accustomed for heavy teamwork. No Python or PHP here. But beware the heavy front-end GUI of Java and Windows-dependent nature of C#/Mono. (Efficient team programming is a whole science by itself.)

However.. In terms of small or medium-sized desktop scripts or engines, with no GUI (ie, automation scripts, etc) then PHP is actually very strong.

Main reason to use PHP for desktop scripting: Training the IT department on the script is half the battle. Unless you are also the IT department (hopefully you aren't), you will find it hard to have this script run on any Windows and Linux computer if you use the common desktop languages like .NET. The libraries and dependencies needed for other languages make them problematic to use across a large set of computers with different operating systems.

That is the main practical reason. Here are more/details:

  • Easy access to MySQL and DBs: PHP is great with quick database scripts.
  • Easy, portable access to a lot of web libraries for HTTP, FTP, MD5, etc.
  • Surprisingly cross platform and easy to distribute: Not only will it run on all OSes, but it is very easy to package the script. You can often even just copy the PHP folder itself. Why is this critical? Keep in mind that programmers are not IT. What happens when IT staff are migrating a server at 2 AM and the code you wrote in 2005 in .NET 2.0 is crashing because of some missing dependency or missing DLL? Personally, I've found this very common. PHP is one of the few langauges that is "well encapsulated" for lack of a better phrase.
  • Very fast development time when it comes to scripting.
  • Execution speed of PHP is slow, but it is hardly noticeable unless you are processing tons of data. If the script runs once a day to process some sort of data, no one will miss the 400ms you saved by writing it in C++. Yet, if you save 5 hours of your own time per year writing and maintaining this script by using PHP, and have more time to add comments to the code because of that, it is better imho.
  • While PHP is loosely typed, you can set error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); and find uninitialized variables. Python is also loosely typed and many use that (Dropbox was made in Python) so I don't see the argument here. It's more the inconsistency of the PHP language.
  • Most external PHP libraries are highly portable and cross platform as well.
  • Low cost to find programmers to help you. PHP programmers are easy to find and relatively low-cost to hire. Both for personal projects and at the work place, this does make a difference. At work, I've often hired people to make PHP automation tools and saved myself time. It might have been more expensive in other languages.

Aside from arguments about whether PHP is a good language overall, what are your criteria for a good desktop programming language (as opposed to web development)? Spoiler: Use .NET/Mono (mono is a cross-platform version of the .NET language) and code in MonoDevelop IDE to ensure your app stays cross-platform from day 1. For Mac, often you will need to tweak things since it's a little different, but you can work with .NET using Xamarin Mac (which is based on Mono but allows MacOS interface components): http://xamarin.com/mac

If Mono/C# is not lean enough due to the dependency overhead, look into Python with PySide. If Python is too slow (although many popular apps like Dropbox use it) then use C++ and the QT framework (used by Skype and many others). I remember Delphi might be another good option, if it even still exists.

Things to keep in mind:

  • 50% of the time, you ultimately need to run as a service or command line tool. So separate your GUI logic from your back-end early on if that's the case. It also lets you make automated test cases.
  • If this is a massively distributed program (like Notepad++, Dropbox, Gtalk) the main thing is good cross-platform user experience. Will Mac and Windows users have a fast-loading app that they feel comfortable with? Or will launching the app feel like pushing a truck up a hill?
  • NOTE: Since most people use Windows, it often makes sense just to use C# or VB.NET and make it a Windows app.
  • Programming speed. Most projects fail because they take too long. It's better to have happy Windows users than no users. Truth is, C# or VB.NET will let you make a great app that works for most people in half the time. And you can likely port most of it to other OSes with Mono. Maybe it's not the #1 fastest in terms of performance or the best overall, but coding in C++ can take too long.
  • Distribution/installers are half the battle. You would be shocked at how many times an app will be completed on Win7 64 bit, only to realize it will crash on XP without some wacky library. Unlike Web, you need to ensure your app works with all OSes and service packs. BIG PAIN! Hint: Test fresh installs using cloud services like GoGrid that let you spin off fresh Windows installs.

I have made complete apps in all these languages, for both internal use and mass-distribution, and that is my 2cents.

Performance is my criteria on desktop software. But I believe that desktop softwares will die someday :)

I'm a huge advocate of using PHP for quick development of web applications. It's easy to learn, has a huge community of other users that have solved most problems already.

However in addition to what other users have mentioned you may also want to consider the sheer number of vulnerabilities PHP already has (http://www.securityfocus.com/vulnerabilities).

If some of these things were addressed and perhaps packaged in something similar to what we see with Adobe AIR, there might be a good basis for desktop application production.

PHP is the new perl if you're going to use it as a programming language outside the web environment. If I'm going to be writing apps, I want a decient environmen to work in. Without 3rd party apps, debugging php programs can be a pain.

I don't see any difference in using PHP for web or desktop application, just different libraries. Qt and GTK+ are both availables to PHP, and if someone took the time to write such bindings it means more than someone is using it for desktop.

In my opinion, the success of PHP in the web is because there is no valid alternative: said in other words PHP is the less worse. In the desktop world it is not so lucky and it should compete with stronger contendents... I'll personally choose tons of other languages before PHP.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top