PHP vs. Perl vs. Java – a student's question.

August 17, 2009

Once and a while, I get a question from a student about PHP and programming that I use in a blog post … here we go again:

… you mentioned that you used to use mostly Java but have switched to mostly PHP. Would you recommend learning PHP as a primary method of creating dynamic web pages or is its strength in data base manipulation. I was learning Perl form processing which led me to your site when I was having trouble with mySQL, and I noticed PHP is very similar (at least in the basics) as Perl. Do you have much experience in using Perl to help create web pages and would you recommend using it at all?

About PHP vs. PERL vs. Java:

PHP is the way to go. Perl is a good language but it was not designed initially for web development – that functionality was added later.

Whereas PHP (which borrows from Perl btw) was designed specifically for web development, and so Perl is just clunkier compared to PHP when it comes to creating dynamic web sites.

I’ve used Perl in the past, mostly creating simple string parsing scripts and other little things. But I would NOT call myself an Perl programmer – so take that into consideration.

That said, I’ve always liked a common strategy used in Perl, where they generate static pages from dynamic code. For example, in our web designers directory, I used a Perl based directory script that uses that strategy.

… What’s interesting is that it generates the directory pages as static HTML pages. The advantage of this is that the directory itself is more portable and much less resource intensive because for the most part, the directory is just of pages that people just read … no need for them to be dynamically generated every time a user request it.

Perl’s Problems

The problem I had with Perl, was its’ practically unreadable code. The language is so flexible in terms of the syntax and structure of the code (for lack of better words) … it becomes esoteric. Trying to decipher old Perl scripts is almost always a nightmare – even for the programmer who wrote it!

Java is great for the enterprise … that means, if you plan to be working for very large companies. But it takes a lot longer to create anything in Java vs PHP. The Java community likes to think their code will be more secure and stable, thus justifying the increased time in development. This perception is simply not true … in fact, my experience has actually shown it to be the opposite.

You can find the SQL videos you were looking for here:

http://www.killerphp.com/mysql/

Stefan

6 Responses

  1. Alexandr Ciornii Author August 18, 2009 at 3:46 am

    In Perl you need to use such tools as Perl::Critic, perltidy, Moose.

  2. amedj Author August 28, 2009 at 12:22 pm

    You should also look into the library support for each programming language. IF you intend to use MYSQL as your database layer, PHP would be the ideal choice since it offers many functions to do just that.
    I would also say that PHP is written primearely for the web application, where as java is for both web and desktop application. Thus, if your application requires integration of both web and desktop application, Java would be a suitable choice..

  3. Michael Kimsal Author September 2, 2009 at 12:33 pm

    Speaking as someone who has been doing PHP since 1996, and made a decent living at it, Java has strengths PHP may never have. Java as a language itself it terribly verbose, and has a slower startup speed, and many other drawbacks. But, using a framework on top of Java – specifically Grails (in my view) makes a lot of web development much much easier than with any PHP code (raw or with any framework).

    I can’t explain the entirety of why I prefer Grails over any PHP framework, but here’s a few:

    GORM – the ORM tool with Grails – makes it easy to express relationships and queries programmatically. Having ‘typed’ class properties allows the framework to infer much more about how to operate than the simple “public/protected/private” which PHP forces on you.

    Private by default – all class properties are private by default, unless otherwise specified. getters and setters are created during compilation, but can be overridden with manually-written code. This saves a tremendous amount of boilerplate code that people used to write in Java (and now most PHP frameworks emulate, because the PHP language itself doesn’t support any other approach).

    Domain-driven design – data models are created in ‘domain’ classes, which are inspected and DB models are created automatically, including relationships, timestamp columns, and automatic ids. Plugins exist for audit logging for any data changes. This allows me to simply design my data objects and run the app – the creation and management of the database (whichever one I want, and Java supports many DBs) is handled for me. Yes, I can override it’s behaviour and decisions if I want to, but I rarely want to do that. Additionally, coming preconfigured with an in-memory database allows for rapid sketching out of ideas without even needing a ‘real’ database to start with.

    Scaffolding – some PHP frameworks offer this as well, so it’s not a total win just for Grails, but it is something which allows people to be pretty productive very rapidly.

    Yes, this is a PHP website, and yes, I still use PHP on a regular basis. I would still encourage people to look outside of the PHP world to learn from other camps, and take time to study those ideas and implementations. You will look at PHP differently, and likely be a better developer for it in the long run.

  4. A dude Author November 13, 2009 at 1:37 pm

    I’ve recently started a blog, the information you provide on this site has helped me tremendously. Thank you for all of your time & work.

  5. Paolo Author January 19, 2010 at 11:40 am

    If we only could do without that $this->attribute thing in PHP. OO languages usually let you access attributes by name and you use this or self (depends on the language) only to resolve ambiguity. PHP programs would be easier to write and to read if we weren’t forced to use $this-> almost on every single line. It becomes noise instead of information.

  6. Stefan Mischook Author January 19, 2010 at 11:45 am

    PHP strength has never been in the elegance of it’s syntax – not that bothers me personally.

To Top