Professional PHP

PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.
« Hump Day Blues
Extreme Simplicity »

Comparing PHP with other languages

February 9th, 2006

Chris Shiflett posted some thoughts on PHP and Ruby on Rails which has generated some interesting discussion. Chris divides programming languages into two categories:

  • Flexible and powerful: PHP, C, C++, and Perl.
  • Structured and organized: Java, Ruby, and ASP.NET.

I don’t disagree with the cultural grouping. PHP’s cultural heritage is definitely in the Unix programming, C/Perl camp as I suggested in building a culture of objects in PHP and Why isn’t PHP the natural successor to Java?

I prefer to group languages in a different way.

Garbage Collection

To me, this is the single biggest language comparison issue. Managing memory is orthogonal to the task most programmers are trying to accomplish. Thats a fancy way of saying a waste of time. Additionally, memory management is easy to screw up. Any process that relies on humans repeatedly doing something correctly is destined for disappointment. Sure, there are tools that help avoid memory management bugs. The best of these is to take it off the programmers plate entirely with garbage collection and let the programmer concentrate on other things.

Sure, there can be resource usage and performance issues. However, for most cases computer hardware is cheaper than computer programmers.

We can divide our languages along this axis:

  • Quickly runs: PHP, Java, Ruby, C#, Perl, Python, Smalltalk
  • Runs quickly: C, C++, Objective C, Delphi

Interestingly, this corresponds fairly closely with native executable versus virtual machine.

Static or Dynamic Typing

The next most important axis of comparison is dynamic or static typing. In static typing type information is associated with the variable. In dynamic typing type information is associated with the value in the variable.

The benefit of dynamic typing is that you do not waste programmer time and attention with typecasting (”static types get in my way”). The benefit of static typing is that the compiler can catch certain errors (”The compiler finds my mistakes”).

  • Risk tolerant: PHP, Ruby, Python, Smalltalk, Perl
  • Risk averse: Java, C#

Interactive or Batch

Some might call this axis interpreted versus compiled. The issue is how long does it take to switch contexts from coding to running? Is there a lengthy build process or a deployment stage? The shorter the build process, the more productive development can be.

  • Interactive: PHP, Ruby
  • Batch: Java

A good example of this in the PHP world is to look at Smarty and Propel. They both generate code to execute. Smarty does it interactively, while Propel requires a build process. The build process is the primary reason I don’t use Propel.

Scope

One should not underestimate the importance of this factor. Why is Java considered so complicated? One reason is that it is designed to run on everything from servers to cell phones, from desktops to dishwashers. It’s scope is impossibly general. Of course, specialized tools such as Rails and PHP are more productive for their sweet spot applications.

  • General: Java, .NET
  • Specific: PHP, Rails

PHP and Ruby on Rails are two peas in a pod

Looking at these factors so far, PHP and Ruby on Rails are two peas in a pod. Lets start looking at some of the factors where Ruby and PHP begin to diverge.

Popularity

Popularity brings better tools, more available developers, better documentation, and better productivity. Programming on a discontinued or rarely used platform is more difficult.

  • Popular: PHP, .NET, Java
  • Rare: Python, Ruby, Smalltalk

Abstraction

Working at a higher level of abstraction allows the programmer to be more productive. The computer industry has continuously been heading up the abstraction scale without looking back. Professional programmers want to work with higher level constructs because they are more expressive. One can get more done with less code. The draw back is that higher level language features can require more programmer skill to use well.

  • Simple: PHP, C, Java
  • Powerful: Ruby, Smalltalk, Lisp

I’m talking about the language, not the libraries when I classify Java as simple. Dynamic versus static typing aside, I see the Java and PHP languages as similarly expressive.

I have alot of respect for Anders Hejlsberg and there is some serious innovation going on in the C# world on this front. Java can barely keep up.

The Rails folks are fond of saying that Rails couldn’t be written without the expressive features of the Ruby language. It would be interesting to get the opinions of some of the cake developers on this idea.

Library Organization

Not my favorite part of PHP.

  • Function oriented: C, PHP
  • Object oriented: Java, .Net, Python, Ruby

Stiffies?

I think Ruby is misclassified when placed with Java and C#. Ruby is closer to PHP than it is to either Java or C#. Rails and PHP share most of the same sources of productivity: garbage collection, dynamic typing, interactivity, and focus on web applications.

Filed Under

  • PHP

Related Posts

  • Ruby versus PHP or There and Back Again
  • James Gosling on PHP
  • Exceptional PHP
  • API Design
  • programming has warped my mind
You can leave a response, or trackback from your own site.

43 Responses to “Comparing PHP with other languages”

  1. smith says:
    2/10/2006 at 2:08 am

    Dude you are totally wrong!
    All over you are comparing .NET witch is a framework with JAVA and Rails (again a framework) with other programming languages such as PHP or Python.
    Why don`t you make a new blog entry where you should compare
    Rails vs. one (or all) +500 PHP frameworks vs. .NET .vs J2EE?

  2. Berislav Lopac says:
    2/10/2006 at 2:17 am

    You have unfortunately missed to mention one of the most advanced, but sadly also the most misunderstood language known today: Javascript. Neglected for years, it’s luckily been gaining momentum lately both on the client side (due to the “ajax” fad) and the server/desktop side (thanks to projects like wxJS or Firecat).

    Javascript has all the familiarity of C, flexibility of Ruby and power of Lisp. Let’s see where it would fall in your analysis:

    Culture: Flexible and powerful
    Garbage collection: Quickly runs
    Typing: Risk tolerant
    Interactivity: Interactive
    Scope: Specific for the most part, but with aspirations to General
    Popularity: Popular on the client-side, Rare elsewhere
    Abstraction: Powerful
    Library organization: Well, here’s a strange beast: while JS is purely OO language, many of its libraries are essentialy nothing more than procedural functions.

  3. Alex Knaub says:
    2/10/2006 at 2:43 am

    a Completion to your classification:

    Strong vs. Weak Typed

    weakly typed: PHP, Perl
    strong typed: Python, Ruby

    Advanced PHP Programming, by George Schlossnagle (Page 484) has a good explanation of the difference between strong and weakly typed languages.

  4. Jeff says:
    2/10/2006 at 7:29 am

    Nice catch, Alex. I missed that one.

  5. Jeff says:
    2/10/2006 at 7:50 am

    Smith, I AM being loose about comparing the language and frameworks. However you cannot really isolate the decision to use a language from the tools that are available for it. The problem is that there are not yet any popular, mature PHP frameworks to compare against. How would I define popular? When it starts showing up in job postings. You can bet that I will write some posts specifically comparing frameworks in the future.

  6. ericfle says:
    2/16/2006 at 1:51 pm

    Hi dude:

    You have other small mistakes in your article.

    1.- [ "Interestingly, this corresponds fairly closely with native executable versus virtual machine. "]

    Efectly, languages like Java and C# run in a virtual machine, but PHP and Perl dont. PHP and Perl are interpreted languages. Olny Perl have a virtual machine named Parrot (Perl 6 or +).

    2.- The section ['Static or Dynamic Typing'] is completely wrong.

    Man, really you dont know about that. The differnece is in the casting form (implicit or explicit). The Interpreter or the compiler always store type information in the variables. Do you want to see a example?

    if you write in PHP:

    $e = 5;
    var_dump($e);

    you show the result: (int)5

  7. Jeff says:
    2/16/2006 at 8:19 pm

    Actually, I’m right on both counts. Internally, PHP uses a virtual machine to execute compiled byte code. Also, if you execute this statement in PHP:

    var_dump(5)

    you will get the same result: (int)5. PHP knows that you passed an integer to the function because the type is associated with the value, not the variable.

  8. Berislav Lopac says:
    2/28/2006 at 5:42 am

    @Alex: How is PHP weakly typed? Each value has its pretty well-defined type… Unless Schlossnagle calls a weakly-typed language the one where type conversions are made automatically?

    @smith & Jeff: Actually, it’s difficult to be very clear about that, because PHP is both a framework *and* a language. Apart from Java, Ruby and Python, which have many frameworks implemented *in themselves* and using themselves as working languages, and .NET which is implemented in whatever and uses several languages, PHP is implemented in C and uses its own syntax for working language.

  9. Ryan says:
    3/9/2006 at 9:18 am

    I’m the author of the Pipeline framework (http://livepipe.net/) which includes a PHP5 ORM layer that has significant similarities with Rails’ ActiveRecord. I wanted to comment on the expressiveness of Ruby, and wether or not Rails can be built in PHP.

    I need to start by saying that I’m only using PHP for this project, and only developed this framework because I think that Rails niche is hosted services (and will someday expand of course), but PHP still reigns king for the total number of users, and people building small to medium sized websites. Anyway, long story short, for a variety of reasons I do not think you can write Rails in PHP. Two main reasons: no closures, no class methods. Static isn’t implemented properly in PHP (in my humble opinion), which prevents things like Article::find() from working. Being able to call class methods “loose” in the class code is actually quite useful and just looks right in a way. I have to admit I was a little confused when I first saw ruby classes a few years back though.

  10. James Gosling on PHP | Professional PHP says:
    3/11/2006 at 9:08 am

    [...] The headline here should be “Father of Java says writing web applications in PHP is simpler.” This is pretty much what I said in my Comparing PHP with other languages post: Why is Java considered so complicated? One reason is that it is designed to run on everything from servers to cell phones, from desktops to dishwashers. It’s scope is impossibly general. Of course, specialized tools such as Rails and PHP are more productive for their sweet spot applications. [...]

  11. Isaac Gouy says:
    3/11/2006 at 11:43 am

    “Quickly runs… Runs quickly”
    Most of the PHP programs on The Computer Language Shootout have been written by a novice PHP programmer.
    http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=php&lang2=ruby

    It would be great if experienced PHP programmers contributed their expertise too show what PHP can do.
    http://shootout.alioth.debian.org/gp4/faq.php#contributeprogram

    best wishes, Isaac

  12. Isaac Gouy says:
    3/11/2006 at 8:26 pm

    “Strong vs. Weak Typed”

    ‘So what is “strong typing”? This appears to be a meaningless phrase, and people often use it in a non-sensical fashion. … If someone uses this phrase, be sure to ask them to define it for you. (For amusement, watch them squirm.)’

    p263 Programming Languages: Application and Interpretation
    http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/

  13. Komodo says:
    4/28/2006 at 2:52 am

    Strong typing isn’t a meaningless phrase; it’s very well-defined. It simply means that all types are known at compile time.

    I would agree with Alex and hence challenge Berislav’s comment that questions how weakly typed PHP really is; PHP is weakly typed, there’s no doubt about it.

    A language like Java is statically (aka strongly) typed, because variables and their types must be explicitly declared, and attempting to store type x under var v of type y throws a type exception.

    PHP on the other hand is dynamically (aka weakly) typed, since the type of a variable is not explicitly declared with the variable itself, and (by casts occurring behind the scenes, I assume) there is little limitation on what can be stored in which variable.

  14. L505 says:
    5/24/2006 at 8:33 pm

    Try passing USD35 or 35USD to a PHP function. Pretend you are building a shopping cart.

    Both are strings. Yet, PHP converts 35USD into an (int)35 while PHP converts USD35 into a (int)0. As a PHP programmer I will sit around and wondering what my types are going to be converted into, instead of knowing what my types are going to be converted into.

    Write unit tests, you say? Sure – unit tests can be written. But unit tests can be written whether it is a dynamic, static, weak, or strong language. You just spend more time writing type checks in your unit tests, if you use a weakly typed language. Sure, you write unit tests that are unrelated to types – but you also write tests that ARE related to types. Writing the tests by hand is in some way more efficient? Not exactly. Writing type check unit tests by hand are actually tedious and time consuming – instead you could be spending your time writing other unit tests.

    So people claim that weak/dynamic and dynamic/strong languages are faster to prototype than strong/static and static/weak languages – but in fact if you must spend more time writing unit tests for your weak/dynamic and dynamic/strong languages, you are essentially reinventing strong typing – and wasting your time.

    All languages end up being strongly typed in the end. Whether you mention your types in your source code comments or whether you test for your times using unit tests, you are essentially reinventing strong typing.

    Not that a compiler which strongly checks your types will solve all your errors. You still write tests for programs, whether they are of dynamic or static, weak or strong type.

  15. L505 says:
    5/24/2006 at 8:42 pm

    And if you (in rare cases) need to pass a special type into your function which is dynamic/weak, but you are using a strongly typed language – you can use an untyped pointer or a variant. A variant is not as fast as a pointer, but a variant is more convenient. There are ways out of a type system in a strongly typed language.

    You can also use an abstract class, but this is a common misconception that the only way to defeat the type system is to use an abstract class. You can use pointers or variants and never have to use an abstract class. But it’s rare that you need this functionality. It’s rare you need to escape the type system. So why make it an essential feature in a language – why not just make it an option. It’s not a feature you want on all the time, so save it for special cases.

  16. Isaac Gouy says:
    6/13/2006 at 7:52 pm

    Komodo, you seem to be using strongly typed as a synonym for statically type checked, and weakly typed as a synonym for dynamically type checked.

    You’ll notice that isn’t what Alex Knaub meant by strongly typed and weakly typed. Python and Ruby are not statically type checked.

  17. Flavio says:
    11/7/2006 at 9:06 am

    PHP sucks so much… Come on, people, PHP started as just a CGI for creating Personal Home Pages (PHP); it has evolved with many retrofits, it’s like converting a VW Beetle to compete in Formula 1; it can be done, it’s fun, but it will not win the race, or it will win it with an absurd amount of effort.

    J2EE is more powerful and ASP.NET/C# is light years ahead PHP. And Ruby surely is the future.

  18. Websites with information on PHP « Krishna Srikanth’s Blog says:
    8/27/2007 at 1:29 am

    [...] http://www.codewalkers.com - articles and sample code http://www.decodephp.com – a blog by a phpian. http://www.procata.com/blog/archives/2006/02/09/comparing-php-with-other-languages/ - Comparing php with other languages http://ilia.ws/archives/12-PHP-Optimization-Tricks.html - [...]

  19. Ruby versus PHP or There and Back Again - Professional PHP says:
    9/23/2007 at 9:37 am

    [...] happens that Ruby and PHP are equivalent in many of the ways that are important. See my post on comparing languages. PHP has some advantages with maturity, while ruby has some constructs, such as closures, that can [...]

  20. Future Programming » Blog Archive » Ruby versus PHP or There and Back Again says:
    6/1/2008 at 5:34 am

    [...] happens that Ruby and PHP are equivalent in many of the ways that are important. See my post on comparing languages. PHP has some advantages with maturity, while ruby has some constructs, such as closures, that can [...]

  21. malaysian hackers says:
    10/19/2008 at 12:58 am

    hey dude…
    why don’t you compare staightly between C++ with PHP???
    its a better comparison though…
    and please don’t compare it too general, include some example would be better..

  22. zalla says:
    3/25/2009 at 9:13 am

    Take a Java example: variable types are known at the compile time. Variable types are immutable.
    Type casting is allowed. Both explicit (by programmer) or implicit by the JVM (widening, autoboxing, etc).
    Once the reference type is declared, it defines the scope of method accessibility as in:

    Class A {
    public void method1 {}
    }
    Class B extends A{
    public void method2 {}
    }
    Class Test
    {
    public static void main (String args[])
    {
    A a = new B();
    a.method2(); // will FAIL since method2 cannot be referenced by type A
    B b = new B();
    b.method2(); //allowed, method can be referenced by the type

    }
    }

  23. Olivier Lalonde says:
    6/5/2009 at 11:38 am

    Very good article although I have to disagree with PHP being function oriented. Since PHP5, all of my applications are heavily object oriented. Frameworks like Zend Framework (http://framework.zend.com) or dORM (http://www.getdorm.com) [disclosure: I wrote dORM] are the living proof that it is possible to write OO code with PHP.

  24. Deripet says:
    9/26/2009 at 6:27 am

    Fully agree with you, about a week ago wrote about the same in his blog!

  25. Jacque Pellam says:
    12/27/2009 at 2:28 pm

    I like what you said here, very informational. I grew up in Memphis and your site brought back many fond memories. What is you favorite place to visit in Memphis? I cannot pick just one, there are too many to choose from. I always enjoyed visits to Graceland.

  26. Baderit says:
    12/30/2009 at 11:44 pm

    Hello friends! Everyone who reads this blog – Happy New Year!

  27. Expert-biz says:
    3/18/2010 at 12:18 am

    It has long been searching for similar information on the Internet, and found only you.

  28. BizExpert says:
    3/19/2010 at 3:22 am

    Very useful information, but the main problem was not disclosed and not understandable.

  29. Valentin says:
    3/20/2010 at 12:34 am

    Country somehow, I doubt that’s true. I need to paint in more detail.

  30. Eden says:
    9/9/2010 at 6:28 am

    Solid webpage. I bought a lot of good knowledge. I?ve been maintaining an eye on this technological innovation for awhile. It is interesting how it retains varying, however a few of the core parts remain the identical. Have you seen a lot alter given that Google produced their latest acquisition within the field?

  31. Keesha Moquin says:
    5/20/2011 at 4:03 pm

    Hi, I used to be searching through the website looking for some data and arrived through your weblog. I am amazed by the info that you’ve got on this site. It exhibits how well you comprehend this subject. Saved this net page, should come again again for lengthy term. You, my buddy, ROCK!!!

  32. test says:
    10/10/2011 at 1:20 am

    Hai

  33. phpacademy says:
    10/10/2011 at 1:32 am

    Regrettably, for many cloud computing platforms the car example you allow doesn’t compute. If you notice an auto as a means to an end, and all of you value is getting there, then you need an application platform like Google’s AppEngine. Here you merely add an app, and it will be managed. If on the other hand you run ec2, you’re no longer thinking about computer hardware, but still about instances and virtual servers. Every one of them run OS’s that need to be maintained; it’s like taking taxi’s but still having to know everything about the taxi’s engines. I predict that sooner or later we’ll move towards AppEngine like models or ‘managed clouds’.

  34. James Gaye says:
    10/27/2011 at 2:38 pm

    Well, I don’t know if that is going to work for myself, however definitely proved helpful for you personally! Excellent publish!

  35. diabities says:
    11/3/2011 at 1:02 am

    Welcome to Causes Of Diabetes Zone! We are the premier site on the Internet for Causes Of Diabetes , Causes Of Diabetes Gear and Causes Of Diabetes …

  36. paving west chester says:
    11/10/2011 at 5:16 pm

    you’ve a terrific blog here! would you prefer to make some invite posts on my blog?

  37. nude erotic art says:
    11/21/2011 at 2:38 am

    At this time there are a bit of engaging elements in time found in this kind of article however , I simply don’t have an understanding if We see virtually all of these center to heart. Right now there is a number of credibility yet somehow We can take hold viewpoint right up until I examine in to it farther. Decent article , Take care. . . and I truly would like even more! Added in to to digg in the process

  38. mira oil says:
    11/22/2011 at 7:42 pm

    Pretty effectively written facts. It’s going to be priceless to any person who usess it, with each other with myself. Sustain the good function ?§C for constructive i will try additional posts.

  39. Amy Axt says:
    1/10/2012 at 5:16 am

    THE EULOGY
    Look not where I was
    For I am not there
    My spirit is free
    I am everywhere

  40. php developer says:
    1/22/2012 at 9:36 pm

    superb information.. thanks for sharing

  41. polštinap?eklad says:
    2/1/2012 at 2:12 pm

    Dobrý ?lánek..

  42. polštinap?eklad says:
    2/1/2012 at 2:15 pm

    Hodnotné info..

  43. p?eklad polština says:
    2/4/2012 at 2:22 am

    Jo to by šlo.

Leave a Reply

Click here to cancel reply.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

code: use [code=php][/code].

Comment Preview

    Subscribe Feed
    Share Subscribe to this blog…
    Share Bookmark or share this page…
  • About

    My name is Jeff Moore. I'm a PHP programmer living in San Francico and working for a startup.

    More about me…

  • Categories (Home)

    • Agile Methods (14)
    • Mac (14)
    • Misc (18)
    • Open Source (14)
    • PHP (99)
    • Software Design (29)
    • Usability (14)
    • Web Design (20)
  • Recent Comments

    • The Legality of Republishing RSS Feeds  28
      Tory Rennemeyer, eenicker, Reverse Phone Lookup [...]
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)  258
      Tuan Lal, Lavagem de estofados, Edward L. Kind [...]
    • php | tek 2008  36
      how to mend ice machine, Akademija Debelih, Odbacena [...]
    • goto in PHP  59
      kasor, Thomas Valdivieso, Murray Ziadie [...]
    • Firefox Extensions for Web Developers  33
      kasor, Website Design Toronto, mobila bistrita [...]
    • Why PHP is easier to learn than Java  68
      kasor, Justina Calvery, Guy Lipton [...]
    • Meta Tag Refresh Faux Paux  43
      html email templates, E-Juice Reviews, image [...]
    • Improved Error Messages in PHP 5  49
      Carroll Tina, Przeprowadzka, Emery Harari [...]
    • Benchmarking PHP's Magic Methods  33
      kayu oyunlar?,dora,oyun,oyna, Benjamin Bejjani, paypal website [...]
    • Microbenchmarks of single and double qouting.  24
      kefir grains minneapolis, sexshop dildo, tuim688 [...]
  • Recent Posts

    • Richard Thomas
    • ZendCon: Writing Maintainable PHP Code
    • Looking Towards the Cloud
    • Holiday Tech Support
    • Closures are coming to PHP
    • php | tek Wrapup
    • php | tek 2008
    • Sarah Snow Stever
    • Benchmarking PHP’s Magic Methods
    • The Endpoints of the Scale of Stupidity on Video
  • Site

    • Archives
    • Log in
  • Search