I recently received the email below. At the risk of starting a flame war, I'm posting my response here.
Hi Matthew,
Sorry to bug you, but I was reading your blog and was hoping you could help me with some advice. I am new to programming and can't quiet make up my mind on which programming language to start with? I started learning php, but have also looked at a bit of java.
I am interested in building web based applications that and am wondering whether I should focus on php, java or python? I have recently read a fair bit about python and some exciting things happening using python. Python seems like an easy , fast and powerful language to use.
Do you have any advice or thoughts on the pros and cons of these 3 languages and what might be the best to start with?
Thanks for your help- and the great blog!!
Hey Sean-
PHP, Java and Python are all good languages and each has it's strengths anad weaknesses.
For web development, php is going to be the easiest to start out with since it was designed for creating websites. However that easiness is going to be lost once you start trying to do more complicated things and inevitably your code will probably turn out quite messy. Lack of support for classes and name spaces for older versions of php tend to aid people in programming sloppily. On the other hand there are a ton of great applications written in php (drupal, mediawiki, sugarcrm, etc), so it is possible to use. If for example your website was based on drupal, you could get a lot of functionality out of the box, and only have to write a small amount of code for missing functionality.
Java has a few things going for it, a big company with marketing dollars and great tools. However the reason it needs good tools/IDEs is because the there is so much syntax that you really want the computer to write all that code overhead for you rather than your fingers. If you are going down the java route make sure to use an IDE like eclipse since it will make your life much easier. I've done a bit of struts programming in my day, and actually don't miss it so much. There's a lot of overhead involved with configuration files that you don't find in php, but that tends to help larger teams coordinate their efforts better. Since moving away from java, I'm not sure what the MVC stack de jour consists of, likely it will include spring and hibernate, as well as other packages.
I'm sure you realized that reading my blog I'm going to favor python. Python is a multiparadigm language so one can program in an object oriented, functional or imperative style. The advantage of this is that there are cases where objects are overkill and get in the way. Sometimes functional constructs just make sense for dealing with some data structures, while an imperative style like C is often the most straightforward solution. Python lets you mix and match that, so with that flexibility also comes power and the ability to program in a way that suites your style. Java is strictly object oriented and PHP until recent versions was imperative with poor support for objects.
Setting up an web development environment is relatively straightforward in python. Both of the web development frameworks I would recommend in python, Django and Pylons, come with built in servers so you can get up and running pretty easy. In java land, struts setup to start a project was a major hassle, but new frameworks might have simplified this. In the php world, one needs to install apache and php, which may or may not be so easy (xampp can help here).
For python development I use emacs, but if you are an IDE type person there are plugins for eclipse, or IDE's such as wing or komodo that have pretty good python support.
I've known quite a few php/java heads who upon learning python haven't looked back. I don't know of any who have gone the other way. Though the lack of static typing/IDE support has proved to be an annoyance to some java developers who have grown accustomed to the niceties of eclipse (code completion, refacoring, error marking).
As far as the Django or Pylons question, Django is probably the best bet for you if you are learning to develop web apps. It has great documentation (plus a good book, that has a free online version), and a great community. It's nearly ideal for greenfield applications, and the admin app is really cool for adding/editing your web models. Django gives you everything you need out of the box.
Pylons on the other hand let's one pick and choose which components to use, rather than forcing one on you. Though the recommended defaults are pretty good. I'm currently using Pylons at work because I have to tie into an existing database, which SQLAlchemy supports wonderfully (and the django ORM just plain wouldn't work with it). So while Pylons gives one the power of choice, that also has an effect on documentation and other factors that make Pylons not quite as integrated overall as Django.
Hope that this (biased) answer helps to bring one more python programmer into the world.
Cheers,
matt
Or use Perl with cgi::application (www.cpan.org) and dive into strange
programming fun.
Chris- I thought I said at the start of the post that I didn't want to
start a flamewar..... Then you go mentioning perl ;)
That's pretty close to the advice I would give -- for an absolute beginner
programmer, PHP will be easiest to start with, because it tries to avoid as
many system administration or deployment issues as possible by being
completely brain-dead. After a while, it could stunt programming growth, so
I'd recommend switching to Python later. (Unless there are specific
packages to make Python work as easily as PHP; then I'd recommend starting
there, but I'm relatively new to Python myself and therefore don't know of
any....) Java is probably useful to know as well, but it might be
incredibly painful to work with after knowing PHP or Python.
Hey Matt,
Python has the advantage in that you much of the code can be done on the
desktop as well. For python on the web - a great way to start is to use
webpy (webpy.org) - in 5 lines of code you can have a working web page.
Also it comes with it's own server and you don't have to mess with Apache,
etc. Another suggestion is to use SQLite as a database. Again it's real
simple and perfectly fine for most small apps. You can always scale up
later with a simple config change.
Sorry Matt. I didn't want to start a flamewar. I recently discovert
CGI::Application and just can't restrain my rapture.
CGI plus python works well, is easy to learn, and most hosts on web have
python preinstalled.
Hi Matt. This is an interesting question and I'd like to re-iterate some
things said here about PHP. I am actually one of those developers you
mentioned -- I learned to program in PHP and switched to Python, never to
look back! PHP is incredibly easy to get running, especially if you bought
the average cheapy shared hosting provider. You literally drop some files
in a directory and you are up and going. It's shared library model (if you
can call it a model) is actually pretty cool too. Most installation
instructions are this: download the zip file, extract it, and stick the
folder in your application. Now type "include 'widgets/widgets.php';"
Woo. This is not only easy on the brain it's also easy on upgrading
because you can upgrade a lib for a single app at a time without affecting
any others in your system.