Sunday, May 18. 2008
Everyone working with PHP is probably asked quite often what the difference is between PHP and Java (or C#/.Net). Besides the usual aspects: scripting vs. compiled and in-process vs. seperate process and Multithreading etc., i think there are some "soft facts" that might be even more important for commercial software development.
For example: In Java (or C#) you can code any architecture for any Problem. Some will need more development time and more hardware, others less. In PHP you still have a lot of ways to solve a problem but not as many as in other languages because of the limits to object lifetime. Some of the possible solutions will lead to a dead-end road in terms of performance and maintainability. Therefore, intelligent PHP developers tend to communicate first. They search for proven solutions, maybe existing PHP-Extensions and working code before defining an architecture (and i dont mean Design Patterns, but examples of working solutions). Maybe it even helps in this case that quite some PHP developers don't have a solid computer science background and therefore they need this kind of inspiration to find a solution at all. On the other side, people tend to be proud if they have something working in PHP thus blog about it and opensource their architecture and code.
Of course you find all this also in Java or C#, but much much more in the PHP area. It seems like the "Not-Invented-Here" syndrome is less mighty here or people are more motivated to share.
Anyway, the result is: Even though there are not so many standards in the PHP world, successful developers have a common understanding about the do's and don'ts in PHP. This unwritten standardization leads to a very interesting fact (also shown in the Plat-Forms contest): PHP solutions of different teams (of comparable skill level) are much more consistent than in Java (or probably C# (Prof. Prechelt, please forgive me this un-scientific deduction)). Meaning: PHP appears more predictable than other programming languages. Now this is a fact that the business decision takers might be interested in...
Display comments as (Linear | Threaded)
I'm sorry but I could not disagree any more, PHP is the promised land for the "not invented here"-syndrome. How often do you see large libraries re-used? Just look at all the hundreds of ORM/db-layer implementations we have lying around.
And trying to make the fact that many php-devs don't have a formal CS background and "need to look at other peoples solution to figure it out themselves" as a good point is just beyond me.
IMHO you often do not benefit as much of reusing code in PHP as you would in other languages because:
- you don't want to go the whole way (ORM is a good example there)
- the code you need is so small that you can write it yourself
But then still the best practices make the solutions very similar again. Even if the code is different (if the developers are experienced ones). Therefore "not-invented-here" might not apply to the actual code but to the concept.
Regarding developers without in-depth computer science background: I think this is one of PHP's assets and fundamental differences to other languages: PHP tries to make coding so simple that even inexperienced users can do it right. These guys show their solutions and look at other's. This gives you a lot of simple examples you can work with as a starting point. IMHO this is an important aspect and always has been a driving force for PHP's success...
Well yeah there are a lot of PHP Developers without a CS backgrounds and that produces a lot of un-reusable code. I know some people who are not able to code PHP but able to find solutions by copy and paste some scripts. But if you have to change them later it´s horroble.
Right. But IMHO this is still better then the same persons trying to code something from scratch...
Well, I have a degree in computer science (MSc conversion course) and trained in Eiffel, Java and Visual Basic. I now use PHP as my language of preference because it avoids all the fiddly bits about connecting up the programming language with the internet, all of which has nothing to do with any real programming I want to do, and similarly all that messing about with the join between HTML and Java which is servlets (yes, I've programmed with them). With regards to borrowing: yes, I do from time to time - and reusability is in the programmer's book of virtues - as well as making my own stuff. I do the former where the nature of the beast is well-established and the latter where it is either a specific function of a new application or I'm just adapting something well-known to meet particular needs.
So you're saying that its a good thing that php developers often poison you're code base with code they found on the net?
imho this is the kind of mentality php should be struggling to distance itself from.
Well i was referring to people with comparable skill-set.
If you only have people who copy code without understanding it, you are of course right. This is what you don't want. But then it's the people, not the fact that they let themselves be inspired by code they find on the net.
Smart developers will search for proven solutions and they will see very soon if a piece of code is good or bad. They will isolate the best ideas and code something new which is hopefully better.
This post is pure, unadulterated flamebait. A lot of theoretical yapping without a single real-world example.
You are right in the aspect that i did not give examples and used a word like "not invented here". Will never do it again.
However, have a look at Plat_Forms.
A litte quote from "How to become a Hacker" from Eric Steven Raymond:
"2. No problem should ever have to be solved twice.
Creative brains are a valuable, limited resource. They shouldn't be wasted on re-inventing the wheel when there are so many fascinating new problems waiting out there.
To behave like a hacker, you have to believe that the thinking time of other hackers is precious — so much so that it's almost a moral duty for you to share information, solve problems and then give the solutions away just so other hackers can solve new problems instead of having to perpetually re-address old ones."
I think this quote fits to the article
... and in our case, the thinking time of the hacker who solved the actual problem once, is valued even more by hundreds of people takign this solution and building their code according to the precious hacker's ideas.
Problem solving is not only the code, it is the ideas behind it. And especially in the PHP wolrd, if the idea is great, the code might only be a few lines...
I think you must use PHP where you find it useful,
Java and C# can be also use where you need to write compile code.
ColdFusion takes half the time to code and is more scalable than PHP. The only benefits which PHP have are that it is free and that it is popular.
Furthermore, it is multi-threaded and can use any Java class as easily as if one were writing directly in Java.
HipHop for PHP transforms PHP source code into highly optimized C++. It was developed by Facebook and was released as open source in early 2010.
HipHop transforms your PHP source code into highly optimized C++ and then compiles it with g++ to build binary files. You keep coding in simpler PHP, then HipHop executes your source code in a semantically equivalent manner and sacrifices some rarely used features – such as eval() – in exchange for improved performance.
Facebook sees about a 50% reduction in CPU usage when serving equal amounts of Web traffic when compared to Apache and PHP. Facebook’s API tier can serve twice the traffic using 30% less CPU.
True, HipHop is cool for companies like Facebook. In my experience, most performance problems result more from bad architecture/design than from pure php execution speed. When you have optimized out your code and scaled already to a couple of hundred servers, HipHop might be an option. But below that, i would discourage its usage since it is not only "eval" that is not working...
nice post but your have discussed java rarely yea php is powerful in web because its servers are cheap as well as development is far more cheap than dot net but you are comparing php versus java come one php is just web programing what else do it build but java it is used in enterprise level possibilities are endless but take a look at some features of java networking, multi threading, game development, software development, web development, algorithm problem solution and many many more do you still think you are comparing a scripting language with java
Oh sorry. Did i forget to mention that i am talking web development here? But on the other hand: Service Architectures more and more tend towards Webservices and Applications become more and more web based (even ERP and CRM these days).
But true: When it comes to sophisticated algorithms and number crunching, PHP is not the language of choice.
On the other side, there are A LOT of very successful browser based massive multiplayer games built in PHP. Multi Threading is something PHP lacks on purpose to stay simple. There are methods in Web Application design how to get around this while keeping the application itself simple. Algorithm problem solution with big computing requirements is usually left to external systems written in C/C++ that are then either embedded into PHP with an extension or via webservices.
Therefore: Yes, PHP is not a general purpose language. And yes: Its execution is not the fastest. See it more like a glue language to connect different C-Libraries and Webservices in a very simple and elegant manner. For this purpose, it works great!
Ich sag' mal, egal wie stark sich das PHP-Team in die Weiterentwicklung von PHP rein he4ngt, egal wieviele Verbesserungen sie dort rein beignn, egal wieviele Sicherheitslfccken sie Schliessen, PHP wird stets hinter Servlet-Containern und .NET-Frameworks herhinken, solange sich die Kollegen, welche dann in PHP entwickeln sich diese neuen Vorzfcge nicht zu Nutze machen. Ich z.B. kenne keine einzige Web-Anwendung, bei welcher z.B. der Safe-Mode eingeschaltet sein darf. Zum zweiten: register-globals und e4hnliche. Zwar halten sich inzwischen sehr viele professionelle Anwendungen an diese Konformite4t, jedoch gibt es immer noch zu viele unabhe4ngige Modul-Enwickler ffcr diese Anwendungen, die sich nicht dran halten, was das Wiedereinschalten von register-globals erforderlich macht. Aber okay. PHP mag ja ffcr Hinz und Kunz -Anwendungen genfcgen, was man unschwer an dessen Verbreitung erkennen kann. Aber von Professionalite4t ist PHP meines Erachtens noch sehr sehr weit entfernt. Warum sind denn wohl JSP/Servlets und ASP/ASPX nicht so verbreitet und warum sind diese Anwendungen um ein vielfaches teurer? Liegts vllt. an dieser simplen Friss oder Stirb -Mentalite4t, welche sich bei PHP-Entwicklern unmerklich einbfcrgert, weil PHP aufgrund seiner Simplizite4t diese schlicht zule4sst?
Das sehe ich anders: safe_mode war ineffektiv und ist deshalb in 5.4 nicht mehr drin. register_globals wird eigentlich schon lange von niemandem mehr benutzt. In PHP hat sich seit langem ein sehr strukturierter Programmiertrend etabliert. Die Anforderungen für register_globals in den von Dir beschriebenen Modulen und Anwendungen habe ich seit langem nicht mehr gesehen. Solche Module sollte man dann nicht verwenden.
Moderne Frameworks wie Symfony2 und Zend Framework2 enforcen dabei immer mehr strukturierte Designansätze. Ich glaube nicht, dass PHP was die Sprache angeht, Java oder gar C# nachhinkt.
PHP is definitely a lot cheaper in the long-term, compared to Java (infrastructure, tools, developers, project times)
I think either PHP or Java can be a great solution for building web applications. However, often PHP is the better choice simply because it is a language that is specifically designed for developing for the web. When it comes to experienced software developers, there is very little difference between one who uses PHP and one who uses Java. An inexperienced developer may suffer from 'Not Invented Here' syndrome, but an experienced developer who is interested in making the best use of his time will understand that a working solution is better than no solution. I find the projection of mental attitudes onto the choice of programming language to be disingenuous, but maybe there is a little truth there - PHP is certainly easier to pick up and make something functional, compared to Java. Even if the functional product is poorly written.