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.

categories PHP
tags java, language-comparison, performance-optimization, PHP, shared-nothing

Related Posts

  • Manual Memory Management is Dead
  • Classpath Considered Harmful
  • PHP Book sales trends versus Java and Ruby
  • The PHP scalability saga continues
  • Crazy Zend PHP Framework Rumors
You can leave a response, or trackback from your own site.

14 Responses to “PHP Development From Java Architects Eye”

  1. #1 Dave responds...
    April 23rd, 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. #2 Sencer responds...
    April 23rd, 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 pingbacked on April 25th, 2005 at 9:28 pm
  4. #4 Angsuman Chakraborty responds...
    April 25th, 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 pingbacked on April 26th, 2005 at 11:08 am
  6. #6 admin responds...
    April 26th, 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. #7 Angsuman Chakraborty responds...
    April 26th, 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. #8 admin responds...
    April 27th, 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. #9 Angsuman Chakraborty responds...
    May 2nd, 2005 at 9:46 am

    Thanks.

  10. #10 FelhoBacsi responds...
    August 6th, 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 pingbacked on January 23rd, 2007 at 11:44 pm
  12. PHP Architectures that power your favourite big websites - TechEnclave pingbacked on September 19th, 2007 at 2:13 pm
  13. #13 Bobrila responds...
    May 8th, 2008 at 12:14 am

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

  14. #14 big responds...
    November 18th, 2008 at 3:43 am

    The parking lot. She whispered. The tap off. Susanne actually, cum filled cunts that one started to.

Leave a 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

  • Search

  • Subscribe

    Subscribe All Posts
    Subscribe All Comments
    Subscribe All Bookmarks
    Subscribe with Bloglines Subscribe with My Yahoo Add to netvibes Subscribe in NewsGator Online Add to Google
  • Share This

  • Categories (Home)

    • Agile Methods (14)
    • Mac (14)
    • Misc (16)
    • Open Source (14)
    • PHP (95)
    • Software Design (28)
    • Usability (14)
    • WACT (7)
    • Web Design (20)
  • Recent Comments

    • The PHP scalability saga continues  20
      mp1e5, mpae1, carc71 [...]
    • goto in PHP  50
      mp7df, mp2be, carc38 [...]
    • WordPress BBCode Plugin  24
      loul, ????????, smolenskiy [...]
    • PHP 5.1 is out  5
      Gorrdon, Joey, alex [...]
    • The value of MVC  10
      Ron, Caren Goodman, Joe [...]
    • PHP Development From Java Architects Eye  10
      big, Bobrila, FelhoBacsi [...]
    • Friendster wrapup: does MySQL scale  11
      autodd4, autoc37, carc20 [...]
    • Mac Mini and PHP  16
      , mp111, mpf64 [...]
    • Keywords and Language Simplicity  8
      sergio, Programmer, Handy [...]
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)  109
      Casper, Andy V, Dedra Church [...]
    • Why is PHP Popular?  27
      booksbrands.ru, megaartic.ru, nedvvid.ru [...]
  • Pages

    • Tags
  • Recent Posts

    • 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)
    • Keywords and Language Simplicity
    • Improved Error Messages in PHP 5
    • Michigan Taxes Graphic Design Services
    • Ruby versus PHP or There and Back Again
  • Archives

    • 2008: May
    • 2007: Jan Feb Mar Apr May Sep Oct Nov
    • 2006: Jan Feb Mar Apr May Jun Jul Oct Nov Dec
    • 2005: Jan Feb Mar Apr May Sep Oct Nov Dec
    • 2004: Apr May Jun Jul Aug Sep Oct Nov
  • Menu

    • Register
    • Log in