7 ms·
"Don't write PHP, write Hack instead" is probably a better title for this post. The author could have chosen to write about PHP best practices that are ignored
by CiPHPerCoder 9y ago
"Don't write PHP, write Hack instead" is probably a better title for this post.
The author could have chosen to write about PHP best practices that are ignored in the ecosystem at large, but instead chose to evangelize HHVM features.
For anyone who currently writes PHP like it's 2009 and wants to learn a better way (without dropping PHP entirely):
http://www.phptherightway.com/ http://www.phptherightway.com/
https://planet.nomadphp.com/ https://planet.nomadphp.com/
https://www.reddit.com/r/phpsec/ https://www.reddit.com/r/phpsec/
If anyone prefers to drop PHP entirely, that's fine too, but that's not the only good answer and pretending that all PHP is bad (like many of the comments on this thread already do) is very disingenuous.
- kyriakos 9y agoGreat comment. PHP has evolved, just avoid old comments on stackoverflow and questionable tutorials, they usually evangelise bad practice and are full of security vulnerabilities.
- astrodust 9y agoGood PHP code tends to look like well structured Java code, but with a rash of $ characters in it. I have to wonder why you don't just write Java and be able to leverage what the JVM ecosystem provides.
- segmondy 9y agoBecause they wish to leverage PHP's ecosystem and Java requires more boilerplate code and tends to be more verbose.
- karlshea 9y agoAlso nobody wants to set up Tomcat.
- kuschku 9y agoThat’s why people use Jetty.
- mschuster91 9y agoAnd Java is notorious for... 1) highly complex (and long!) build processes 2) memory issues: I have yet to see a reasonably complex Java application, both desktop and web, use a reasonable amount of RAM. Also, the fact that the JRE is long-running inevitably leads to memory leaks whereas in PHP every request and its environment get torn down at its end 3) overabstraction and literally hundred-lines-long stack traces which make debugging next to impossible. However, the trend seems to be heading this way in PHP too, so I don't know how long that advantage still holds.
- karlshea 9y ago> overabstraction and literally hundred-lines-long stack traces which make debugging next to impossible. However, the trend seems to be heading this way in PHP too, so I don't know how long that advantage still holds. Definitely true. Laravel has this issue with the added bonus of magic methods and Facades all over the place.
- deweller 9y agoAre you aware of what the PHP ecosystem provides? There is some pretty great stuff in PHP land. 2 of my favorites are https://getcomposer.org/ https://getcomposer.org/ and https://laravel.com/ https://laravel.com/
- 0xJRS 9y agoHavent worked in PHP in a few years but when I did both composer and laravel were amazing.
- g00gler 9y agoLaravel looks just like a well structured Java program assuming you use strong types as the rest of the framework does. :P Edit: that's not to refute what you've said or anything.
- karlshea 9y agoIt really does. Java was the language I learned on, and it's super great that I can use all of those patterns nowadays. PHP is the typical expectation for clients that need a CMS, and it no longer feels like quite the cesspool it was five years ago. Composer and the PSR initiatives have totally changed the feel of working in this ecosystem for the better.
- astrodust 9y agoHonestly, that's like a cup of ice water in hell. Composer is a finally thing, and Laravel is a "at least it's not garbage" framework. The things you have to make do with in the PHP world are absurd. Find something in an array? Ugh. PHP is catching up to what other languages have enjoyed as a given for over a decade. It's very confused. There's been absolutely zero effort to overhaul the core PHP API which is, on the whole, absolute junk. Frameworks like Laravel do their utmost to insulate you from having to use it too much for the ugly things. As an example of what could happen, JavaScript has gone from this ugly, useless language that would crash your browser if used too much to something that's now widely deployed and powers significant web properties both client-side and server. The improvements to the language have been dramatic, ES6 code is words apart from JavaScript 1. In another 5 years JavaScript will hit another milestone, Java will evolve, and PHP will still be PHP.
- CiPHPerCoder 9y ago82% of the websites on the Internet are powered by PHP, not Java. A lot of these decisions are based on "what will pay the bills today and in the immediate future?" rather than purist idealism. A lot of businesses use Java. Java experience is more useful for getting into mobile app development with Android. There's value to be had in learning and writing Java. But the demand for PHP doesn't cease to exist because Java is cool or useful. https://w3techs.com/technologies/overview/programming_language/all https://w3techs.com/technologies/overview/programming_langua...
- astrodust 9y ago82% of business applications used to be written with COBOL or FORTRAN. What's your point? Things change, sometimes dramatically. PHP has vastly out-lived its welcome. I'm not saying Java is immeasurably better, it's got a whole different set of problems, but it's an example of a language that's got a better tool-set than PHP ever will. The debugging tools for Java are really amazing because writing good, threaded Java code can be wickedly hard. The tools for PHP are absolutely anemic by comparison because it's never had the same exposure to enterprise environments. I'm no fan of Java, but if you're writing Java, you may as well write Java.
- voidr 9y ago> 82% of business applications used to be written with COBOL or FORTRAN. 'used to be' being the key words here. PHP is __still__ being used. > PHP has vastly out-lived its welcome. Care to explain why you believe that? C is older than PHP and is still around. > but it's an example of a language that's got a better tool-set than PHP ever will. Don't know about the PHP toolset you have been using, but I take Composer over Maven any day. If you are talking about IDE support, PHP7 IDE support is as good as Java IDE support. Can you give me examples of tools that are better in Java? > The debugging tools for Java are really amazing because writing good, threaded Java code can be wickedly hard. The tools for PHP are absolutely anemic by comparison because it's never had the same exposure to enterprise environments. PHP web applications use a process-based model, therefore debugging threads is irrelevant. > I'm no fan of Java, but if you're writing Java, you may as well write Java. I recommend you try out the latest Spring framework(Java) and then go try out the latest Symfony(PHP) and you'll see why you would want to use PHP in some cases despite it having similar OOisms.
- anotherbrownguy 9y ago- Too much boilerplate - Existing Java frameworks and libraries are difficult to obtain and maintain and difficult to work with (PHP libraries/frameworks are available in central repository - packagist, and are on github) - Not much difference in performance - because most operations are IO bound in web context - also, PHP extensions are implemented in C - so you could implement your performance-critical parts as a C extension (or if your architecture allows it, in any other language and run as a different service communicating async with your application)
- brightball 9y agoAnd because PHP scales DOWN better than Java making it tremendously cheaper to host for low traffic sites (aka - most sites).
- fweespeech 9y agoAs someone whose parent company is a Java shop....Plz no. The amount of boilerplate in "good" Java code is substantial (like 20-30% more lines) compared to "good" PHP in practice. At least imho/experience.
- deleted 9y ago[deleted]