About

Welcome to Panela, Matt Harrison's take on mostly Open Source, Linux, Python, innovation in those areas, other buzzwords and Dick Proenneke. It comes complete with the illustrations as needed. Note the opinions expressed here are merely my opinions and not the opinions of my employer.

about Matt

Calendar

««Jul 2009»»
SMTWTFS
    1234
567891011
12131415161718
19202122232425
262728293031

Mailing List

My RSS Feeds








Ask Matt: Java, PHP or Python for beginning web development?

posted 2008.03.06 Thu

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!!

My response

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

tags:                    

links: digg this    del.icio.us    reddit




1. chris left...
2008.03.06 Thu 5:24 pm

Or use Perl with cgi::application (www.cpan.org) and dive into strange programming fun.


2. Matt left...
2008.03.06 Thu 5:32 pm :: http://panela.blog-city.com/

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 ;)


3. sapphirecat left...
2008.03.06 Thu 6:34 pm :: http://www.sapphirepaw.org/

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.


4. Krys left...
2008.03.06 Thu 8:03 pm

Hey Matt,

I think you gave a pretty balanced answer. I would only add two additional points:

1. It's easier to deploy PHP on cheap hosting services, which may or may not need to be factored in the decision. For Python, you have to find a hosting package that supports it.

2. Even though PHP might be easier to get started in, I also teaches you to program sloppily (as you mentioned!). So maybe starting with Python would be a better choice. You still hit the ground running, maybe not quite as quickly, but you end up a better programmer in the long run by not having to unlearn your previously learned sloppiness. Learn it "right" the first time, as it were. Just a thought.

Anyway, great response. I hope it helps.

Good luck Sean! :)

Krys

P.S. I'd also recommend watching for TurboGears 2.0 when it comes out. It'll have all the Pylons-y goodness, but may be easier to get started with.


5. john left...
2008.03.06 Thu 8:57 pm

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.


6. chris left...
2008.03.07 Fri 5:54 am

Sorry Matt. I didn't want to start a flamewar. I recently discovert CGI::Application and just can't restrain my rapture.


7. ToddB left...
2008.03.07 Fri 9:16 am

CGI plus python works well, is easy to learn, and most hosts on web have python preinstalled.


8. Kumar McMillan left...
2008.03.07 Fri 12:46 pm :: http://farmdev.com/

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.

But yes as life moves on you realize that mixing HTML and code was not a good idea and maybe you start using include "my_whole_site.php" at the top of each page but it doesn't make things much better, you started learning SQL and you have hard-coded select statements everywhere, you have long winded function names and they're all in one file called functions.php ... then you realize you never wrote any tests because no one suggested to write tests and no library you downloaded had any tests. *sigh*. So it was a long hard road for me and now, here I am, using Python everyday, knowing about all those things: when to use functions, when to use objects, WSGI, database abstraction layers, how to do this, that, and the other.

Bottom line: PHP is a really great newbie language and the community is ginormous, the amount of "help, how do I do <blah>!" documentation is also ginormous, deployment is easy, 3rd party packages are vast but like everyone else said, you are going be a much more productive newbie if you start learning in Python! And, yes, Django is by far the best Python newbie tool and is also supported by a lot of shared hosts these days, I think.

I am often fond of my PHP days but mostly this is for nostalgic reasons. It was an exciting time in my life where I first realized how rewarding it is to build complex software. However, I realized that managing this complexity was not so exciting and this lead to throwing away a lot of code and starting over -- a newbie in any language will have to do this. Now, managing and scaling complexity is exciting again because I have a better handle on it ... and I have regression tests! (btw, looking forward to your talk at PyCon! :))


9. PHP Victim left...
2008.03.07 Fri 9:32 pm

Friends don't let friends use PHP.