Professional PHP

PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.
« PHP versus ASP
Expert and Novice Programmers »

PHP Development From Java Architects Eye

April 23rd, 2005

Simple Thoughts blog has a post on PHP development from a Java architects eyes. This post highlights the paradigm difference between programming in PHP and programming in Java:

In PHP multi-threaded programming using ticks is rather primitive, to put it politely. I couldn’t find any way to share data between multiple invocations of the script, without resorting to file or SQL. I missed saving in servlet context and singletons (evil!).

I however kept looking for a uber-global which will allow me to persist data across sessions.

I couldn’t find simple way to cache data in PHP. File or DB based caching was unattractive to me.

This pretty much sums up the fundamental difference. PHP shuns threads in favor of simplicity and relies on files and databases to “share data between multiple invocations of the script.” The author doesn’t make this paradigm shift and erroneously implies that PHP is not scalable. At the same time, he offers this insight into the mindset of Java programmers:

I think it is because Java think-tank wants to encourage programming with resource constraints in mind. remember Java had an Oak background, a language targeted for limited resource devices.

The sad part is that most Java developers get bogged down by such trivialities and cannot see the forest for trees. I know, I know you are an exception.

Most of the time you hear Java programmers thinking of scalability and performance when his PHP counterparts are happily coding away in a world with unlimited resources (they think). Unfortunately Java developers as a group tend to get bogged down with resource conservation mindset.

There is a name for this. It is called premature optimization. And it often leads to code that is slower and less scalable. Scalable applications can be written in PHP. One just uses a different set of patterns to write them in PHP than in Java.

Speaking of mindset…

Overall a large part of the difference is in the mindset of a Java and PHP developer. How do you perform SQL queries in PHP? You just create a SQL statement string in code concatenating proper parameters as necessary.

Tell that to a Java programmers worth his salt. If he doesn’t half-die in shock, I would be surprised. … At the very least he must stow away his SQL code in a separate class and use the functionality by invoking methods in that object.

PHP pitches a large tent. There are many amateur and professional programmers using PHP. I don’t know many of the professionals using this technique. Most people I know are using a data base abstraction library, such as PEAR:DB, PEAR:MDB2, or ADODB, Creole or perhaps even PDO.

The interesting thing is that some of the most popular PHP applications are not the ones that I would point to and tell people “this is a good example of programming in PHP.” I won’t name names, but I would hate for people to form their opinions about PHP solely on the design of these applications.

I got my first paid full time programming job over the summer when I was 17 and worked as a full time professional programmer during all but two years of my college career. Eventually I came to a realization that caused me to change my major from computer science to business. That realization was that project success has far more to do with how closely your software meets requirements than how technically advanced it is. I have personally witnessed far more “high architecture” projects that never finished or met the users needs than “low architecture” projects that couldn’t be made to scale when necessary.

That is why software built by their users, such as many visible PHP projects are, can be very successful. They do exactly what the users would want them to do. Then we professional programmers look under the hood and and turn a little green. However, sometimes worse is better.

Filed Under

  • PHP

Related Posts

  • Manual Memory Management is Dead
  • The PHP scalability saga continues
  • Classpath Considered Harmful
  • PHP Book sales trends versus Java and Ruby
  • Agile Development for an Agile Military
You can leave a response, or trackback from your own site.

14 Responses to “PHP Development From Java Architects Eye”

  1. Dave says:
    4/23/2005 at 1:19 pm

    There are certainly times when threads are nice to have. An application I worked on took a request via HTTP, and then simultaneously sent it on to multiple parties. The results were then aggregated and returned to the original poster. This was very easy to do by creating extra threads.

    I could do that in PHP, but it would require programming at the socket level using poll() or select() or kicking of extra processes, or something not as obvious as threads.

  2. Sencer says:
    4/23/2005 at 3:47 pm

    Good find and nice analysis. I hate me too posts, but to this I cannot say much more than “I agree”, and that I actually had the imminent urge to so in writing.

  3. Ryan Brooks Dot Net » Blog Archive » Bootstrap Progress says:
    4/25/2005 at 9:28 pm

    [...] ient was missing a field name in the database, their system would break. Jeff Moore made a post about this exact problem – he called it premature [...]

  4. Angsuman Chakraborty says:
    4/25/2005 at 9:41 pm

    > The author doesn’t make this paradigm shift and erroneously implies that PHP is not scalable.

    I am not assuming anything here. I am stating the facts as I see it :)

    Opening and writing to multiple files in the course of serving a single request doesn’t improve scalability. Specially when you are trying to scale across multiple machines. No amount of imaginary paradigm shift isn’t going to change that. Such practices also makes php a low throughput system.

    > There is a name for this. It is called premature optimization.

    You have mis-named it. It is called *architecture and design*.
    I was talking about thinking, not optimizing then.

    > PHP pitches a large tent. There are many amateur and professional programmers using PHP.

    You bet. Unfortunately most of the much-talked open source php projects have a significant share of these amateur developers.

    > The interesting thing is that some of the most popular PHP applications are not the ones that I would point to and tell people “this is a good example of programming in PHP.” I won’t name names, but I would hate for people to form their opinions about PHP solely on the design of these applications.

    I agree. Please do point me to some succesful php projects of exmplary code.

    > That realization was that project success has far more to do with how closely your software meets requirements than how technically advanced it is.

    It also has to do with how manageable and maintainable a project is over the long run. I have seen too many projects with “amateur” coding became so unmaintainable so fast that they had to be abandoned and had to go for total rewrite.

    > “high architecture” projects that never finished

    I don’t know what “high architecture” means. However you are probably referring to over-architected projects. A good projects stands on optimal architecture, nothing more nothing less.

    > That is why software built by their users, such as many visible PHP projects are, can be very successful.

    The arguments don’t stand up. You are trying to prove a point that isn’t there. Programming is about programmers. Some language make it easy to write bad code like php or perl, some language make it harder like Java or C#. However bad code can be written anywhere.

    Having none or minimal architecture in a project doesn’t make it a candidate for success or make it more suitable to meet customer requirements.

    If you are looking for minimal architecture approach then you may be interested in extreme programming. XP projects are very successful in meeting customer requirements as the projects revolves around the customer all the time.
    Interestingly there are more XP programmers in Java then in all other languages combined.

    I think you need to delve deeply into Java, which will dispel lot of myth you have regarding Java.

  5. Simple Thoughts » Archive » Re: Re: PHP development practices from a Java Architects eye says:
    4/26/2005 at 11:08 am

    [...] elopment practices from a Java Architects eye, Jeff Moore had some thoughts. I posted my response (to his reponse to my p [...]

  6. admin says:
    4/26/2005 at 1:37 pm

    Opening and writing to multiple files in the course of serving a single request doesn’t improve scalability. Specially when you are trying to scale across multiple machines.

    Coupled with a shared file system, such as NFS, files can be a very appropriate way to share infrequently changed data across several machines.

    No amount of imaginary paradigm shift isn’t going to change that. Such practices also makes php a low throughput system.

    I’m not trying to make the point that PHP scales better than java. Just that it is incorrect to think that it can’t scale. I am trying to make the point that one uses different techniques in PHP than Java to accomplish the same thing. That is what I meant by paradigm shift.

    You have mis-named it. It is called *architecture and design*.
    I was talking about thinking, not optimizing then.

    Ok, I was just trying to point out that thinking about optimizing too much during design is premature. I thought thats what you were trying to point out, too.

    You are trying to prove a point that isn’t there. Programming is about programmers.

    But software projects are about delivering value to your customers, not about programming. Thats why I stopped taking Engineering classes and started taking MBA classes.

    It also has to do with how manageable and maintainable a project is over the long run. I have seen too many projects with “amateur” coding became so unmaintainable so fast that they had to be abandoned and had to go for total rewrite.

    And sadly, I’ve seen some of those “amateur” projects chug along, working for years while the “professional” rewrite fails to catch up. Re-writing is risky business. Whenever a programmer says “this code is too crappy to change, lets re-write the whole thing,” I change that in my mind to “I’m not talented enough or patient enough to fix this crappy code.” Especially if they are under 30 years old. Hows that for a paradigm shift? :)

    I worked on three generations of manufacturing ERP system over the course of 9 1/2 years. That system was deployed into about 45 somewhat independent installations, replacing several different existing custom solutions. Over the course of this process I was able to see the long term consequences of many technical decisions. I was also able to see several different independent implementations of the same thing. This is where I gained a healthy respect for the ability of “amateur” programmers to write code that successfully meets user requirements. I also learned that technically sound projects can fail spectacularly.

    Would it surprise you to learn that one of my last tasks on this ERP system was to begin the migration of the next version to Java? I might know more Java than you think. Then again, I may know less than I think. :)

    I am familiar with XP practices. I deploy my unit tested PHP application weekly, thank you. :) Interestingly, PHP has a small active community embracing XP principles.

    I’m going to address the good example issue in a new post.

  7. Angsuman Chakraborty says:
    4/26/2005 at 8:39 pm

    > Whenever a programmer says “this code is too crappy to change, lets re-write the whole thing,” I change that in my mind to “I’m not talented enough or patient enough to fix this crappy code.” Especially if they are under 30 years old. Hows that for a paradigm shift?

    It’s not a question of talent. There is only so much s*t you can handle before you just throw up :) Some code are like that. Sure one can spend time in trying to fix it. But then when you are fixing something which is poorly architected and designed in the first place, you are most likely going for band-aid solutions.

    BTW: This is the reason any programmer worth his salt never says “rewrite” to management. He says “refactor”. That word is very management friendly. How’s that for a paradigm shift ;)

    > But software projects are about delivering value to your customers, not about programming.

    Yes. Also at the end of the day a programmer needs some job satisfaction out of it. There are human beings on both side of the equation. I think XP achieves both with a remarkable degree – customer satisfaction and programmer satisfaction.

    > “infrequently changed data”
    I agree. That’s the key point. Not when you are also modifying the file at every request however. Then a DB is a better
    choice.

    > Just that it is incorrect to think that it can’t scale.

    I never even thought that. Definitely you can scale it across multiple machines. My point was that it will have lower performance in hardware utilization and certain prevalent (yet bad) practices makes it harder to scale. The key issue about scalability is how linear is the curve and how long does it maintain the linearity.

    BTW: Does PHP have some coding standards or best practices guidelines? That might help in reducing some bad php coding practices I have seen in rather famous Open Source projects.

    > I might know more Java than you think.

    I wasn’t trying to undermine your Java knowledge.
    It’s just a vast subject. It is not possible for everyone to know everything. I am working in Java since ‘96. I don’t claim to know everything, far from it. I am learning everyday.

    > I deploy my unit tested PHP application weekly, thank you.

    That sounds great. I would love to know what kind of challenges, if any, you face implementing XP practices in PHP.

    Are you using phpunit?

  8. admin says:
    4/27/2005 at 3:50 am

    You might look at the PEAR coding standards.

    SitePoint’s Advanced PHP Forum is the place to learn best practices in PHP. My handle is Selkirk there.

    I am using SimpleTest.

  9. Angsuman Chakraborty says:
    5/2/2005 at 9:46 am

    Thanks.

  10. FelhoBacsi says:
    8/6/2005 at 11:03 am

    Angusamn: you should take a look the wact project. (wact.sourceforge.net)

  11. Ajit K » Link: PHP Development From Java Architects Eye says:
    1/23/2007 at 11:44 pm

    [...] Here is a nice read about “PHP Development From Java Architects Eye“. I could feel the same thing right now as I am trying to use PHP for webev. [...]

  12. PHP Architectures that power your favourite big websites - TechEnclave says:
    9/19/2007 at 2:13 pm

    [...] "Scalable Internet Architectures"High Performance PHPFriendstar switching from JSP to PHPPHP Development From Java Architects EyeGetting Rich with PHPJames Gosling, the "father of Java," commenting on PHPNice blog at [...]

  13. Bobrila says:
    5/8/2008 at 12:14 am

    Try to look here and may be you find what do you want:,

  14. qmenqyqh says:
    12/1/2008 at 2:41 pm

    In my ankles like to breathe. Im running out ashley tisdale porn any realistic detail. I could tell.

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 (17)
    • Open Source (14)
    • PHP (98)
    • Software Design (29)
    • Usability (14)
    • Web Design (20)
  • Recent Comments

    • Programming Language Trends via Google  19
      Craigslist pva, jessica, Scott [...]
    • Looking Towards the Cloud  35
      bentonville multiple listing, cosmetic dental, Sam Brodish [...]
    • PHP versus ASP  8
      Marhta Blight, Ravi, Ryan Brooks [...]
    • How to Transfer Mac OS X Application Data between Computers  59
      Website Migration, harry the computer support guy, Dotty Salvage [...]
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)  157
      lehuuphuc, Robert Parthemer, Lingerie Intimate [...]
    • PHP Games  25
      jessica, Tennille Cranor at Chilli Plants, Lucas Ortell [...]
    • un-PEAR-ing  5
      jessica, Eugene Panin, Arnaud [...]
    • The Legality of Republishing RSS Feeds  23
      kevinxiao, Marissa Miscovich, Quick Student Loans [...]
    • Faster Page Loading  4
      jessica, angular cheilitis, Aaron Rosenfeld [...]
    • PDO versus MDB2  15
      jessica, kevinxiao, Gavin [...]
  • Recent Posts

    • 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
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)
  • Site

    • Archives
    • Log in
  • Search