Taking PHP Seriously
slack.engineering
slack.engineering
I'm convinced the reason so many successful projects use PHP, is not because of any inherent nature of the language. I think it's the people who use it. They just don't care. A successful project needs to be started by someone that cares just enough, but not too much.
If you're programming in PHP, you're not running around talking about "convention over configuration" giving talks, or trying to make your code beautiful. It's a garbage language, and you know it. But it allows you to get something up and running, so dang quick. You're failing while the other guy is still updating his gem file. You're advertising while the other guy is trying out some fancy new deploy script. You're incorporating feedback while the other guy is just starting to get to work. When he finally fails, he's used up half his runway, whereas you, the guy who didn't give a fuck about your code has gotten past that first failure, and are finally getting some traction.
Hopefully, the next guy to join the company will clean up your shit. The other guys code may not look like shit, but it doesn't solve any useful problems... so they never got the chance to hire that next guy.
Some companies are succeeding in spite of php. There are many, many users of php, and we'd expect that there would be considerable variance, with some users doing awful (no traction, buggy sites, etc) and some hitting home runs (facebook). Because it's such a popular language, it will have users across this entire spectrum.
It's easy to cherry-pick the winners and miss all of the tremendous losers who picked php and got nothing for it.
Only engineers care about programming languages. Seriously. That's it. No one else cares about them. I work in a large public university alongside a revolving door of student interns who are always 19. In 10+ years of work, I've still yet to meet the person who talked about their favourite website or app, but lamented that it was written in Php or JavaScript or Go or Java. It's only us (the HN'ers) who fret about this.
Don't believe me? Imagine the look on everyone's faces at the tech publishing houses around 2009 when books about Objective-C sold a few hundred copies a year to doing tens of thousands per month when the iPhone rocked the world. This happened without a proper language hot stove on Hacker News, no?
People care about outcomes. People care about products. People care about being dazzled. People care about showing their friends this incredible thing they saw on the web/this new app.
Asking as I've developed in a slew of languages and never found the PHP-bashing credible. Most of the complaints seem to come from Rails people, but there are no shortage of MVC frameworks in PHP, including at least one that is a direct clone of Rails.
The language you use pay second- and third order dividends, but most battles are fought and won on first order.
I'm a C++ developer, have shipped Java and C# and Haskell and Python and a bunch of other code in production. If a friend asks me to spin up a website for him/her quickly, I'd still do it in PHP.
Horses for courses.
Some companies are succeeding in spite of [insert language]. There are many, many users of [insert language], and we'd expect that there would be considerable variance, with some users doing awful (no traction, buggy sites, etc) and some hitting home runs (facebook). Because it's such a popular language, it will have users across this entire spectrum.
It's easy to cherry-pick the winners and miss all of the tremendous losers who picked [insert language] and got nothing for it.
This is exactly right. The right philosophy for PHP is to embrace the garbage. When you're done with a request, and have spit out all the HTML to the client, the server is going to throw everything away. So don't build a beautiful object tree to describe everything, just do the minimum amount of work to take the garbage input and generate the garbage output, and be done. Don't worry too much about your code being beautiful, because it lives in a dump.
This may sound negative, but working in a dump means you don't have to worry about appearances while you do what you came to do. You can always take a shower on the way out :)
PHP didn't succeed because of the "language" part. It succeeded because it was limited and focussed to just being a tool to write small web-apps in a short time.
It did one thing and did it better than anything else of the same era (I built CGI apps in C, Perl and Python before discovering PHP).
It was just files, that you ftp-d in and it just worked.
99% of the friction is in writing the first thousand lines of code and PHP meant that nearly all of those lines was business logic, not unescaping POST data or parsing GET parameters.
PHP doesn't remove your ability to think clearly. It is true that it does not provide helpful additions for algorithmic work, but it does not put challenges in your way when writing web-apps. And yet, it does not force you into too much magic about how it works - just enough abstraction for a messy coder.
All other solutions, java, .net, node, python, Haskell, etc require you to run and maintain your own servers. A minor exception for CGI based solutions but those were all too heavy.
Some good programmers genuinely point out some of the pain points of php, but most programmers paint php as shit just to show off as a good programmer.
I would argue that it still does. It's not a great language, but to just get something working I still can't think of anything better that doesn't require lots of planning or infrastructure
So much time wasted talking about the "right" way to build software, and the best technologies to use, taking positions to bolster your CV or make a name for yourself, and nowhere near enough emphasis on shipping useful, working software.
It drives me slightly nuts. Many people don't realise that technical debt is often a great problem to have because it means you've succeeded. They also want to live in this reality distortion field where they ignore the fact that the code they write today is tomorrow's technical debt because, for reasons I don't fully grasp, they think they're going to do it "right" this time. To quote from Garth Marenghi's Darkplace: "Uh-huh? Bye." In 5 years' time our successors will be wandering around moaning about the crappy code we wrote today, but only if we succeed.
If PHP is the fastest route you know to releasing something worthwhile then more power to you.
(Just to be clear though: I'm not advocating an end justifies means approach to all areas of life.)
V1 is usually shit in any language and if it does what it's supposed to do, it remains shit forever. I've seen shit in C#, Java, and ROR. I've seen stored procedures stringed together inside MSSQL Server vomiting HTML snippets and PS shells giving birth to Excel files to be consumed via network share by some poor soul pressing a button in Excel. I've seen systems written in "enterprise" style, by "enterprise" developers without a single automated test and 20+ levels of abstraction with cross-dependencies running like spider web among 10-some "sub-projects".
I'm not even talking about time-tested shell scripts you can find included by default in your favorite distro or the widely beloved ./configure.
I guess the point is, the language has nothing to do with the attitude of the developer / project manager / product owner. It's easy and convenient to just dump your problems on the tool you're using, but the reality is more deeply rooted in the whole approach to software development (just get shit done), project management (the requirements have just changed, dude!) and the general "i need it done last week" attitude of the product owners.
But sure, let's collectively shit on PHP, just because it's easier. Just like writing shit code is.
I started my career as a PHP developer. Any web project you prototype in C# could be prototyped in PHP in a small fraction of the time.
Finally, good luck with writing a unit test against an API not created by you because, you have to go through deep into the source code just for figuring out what data structure return and give.
However what I find incorrect is the claim that Ruby is a garbage language. Then again, maybe that is best treated as hyperbole, as an exaggerated expression of your dislike for it.
Is that a good idea?
There's a reason that people claim (incorrectly, but still) that somewhere inside of Javascript there's a Scheme dialect, desparately trying to get out. This isn't true, but the proper lambdas and scoping are very scheme-esque.
Theres a lot of raise ArgumentError.new unless foo.kind_of? Bar
Going on in my code these days.
I think JS is better than PHP, at least when it comes to: 1.) consistency of std lib and 2.) type casting. There are many surprises with PHP's type casting. See /r/lolphp sorted from top all-time: https://www.reddit.com/r/lolphp/top/?sort=top&t=all
Whatever I would say about PHP - how good or bad is - I am almost forced to use it - In central/eastern europe almost any company uses it to develop web-backend... but I really would love to jump to Node/Go/Golang-based development team (maybe even remotely).
[1]: http://laravel-recipes.com/recipes/60/optimizing-the-framewo...
- You sit in a dining table with 50 different utensils. White wine glass, red wine glass, water cup, salad fork, dinner fork, dinner knife, teaspoon, soup spoon, bread plate with knife...
- When the food is served, you take the food, drop it on the floor, eat it with your face (not even using your hands).
"get shit done"... use spoon as a knife and knife as a fork, or try to sniff your food through your nose instead of eating it.
If PHP gets you to first base (MVP) in 10% of the time than NiceLangX then you get 10 X more chances to throw shit at the wall and see what sticks.
It is probably ok if you work for a startup that does not survive long enough for the quality of your code to matter anyway. But in a regular company, your attitude creates a time bomb when eventually any apparently simple change may destroy the codebase (and at best, it just takes too long to make any change).
Bad code isn't Technical Debt, it's an unhedged Call Option http://higherorderlogic.com/2010/07/bad-code-isnt-technical-...
I do my part today by acknowledging all of my code is bad, therefore I don't invest a lot of time or ego in it. I try to make it in reasonably sized pieces so it's easier to rip out later (this may make it slightly less bad). If someone comes and tells me my code is terrible, I say yes it is, you might want to consider these things when you replace it.
EDIT: my opinions on this would change if I were shipping code to run on other people's machines: it's generally easy and quick to fix my code on machines I run, but updating code on other people may never update, you need to try harder to get it right the first time.
A couple of months back there was this php sucks article about being looked down upon because you do php for a living. Php is the language people bitch about to feel better about themselves. Even within the php community symfony developers don't take drupal developers seriously. It's sad really and even I'm guilty of doing that. A little more respect for your fellow developers is all we need. It's like judging a book by it's cover. How would you feel if <insert your fav lang> was treated that way.
Php has a lot going for it. The community is very active and passionate, new things come out at a rate you can keep up with. You can easily get passionate about it if you engage in it. A lot of interesting projects are (being) build with it and it is obvious that php won't disappear anytime soon.
If you have to work with php and bitch about it, make the effort and solve the problem you have with it. Contribute back to the community and experience the gratitude. You'll enjoy your work more.
So there are php people that care and they try to make the best of it. I don't think they consider it to be a garbage language. They are the ones that made php what it is today which is something totally different compared to what it was years ago.
But business success is largely orthogonal to language choice. I.e. when you buy a paid Github plan do you check what language they write the site in?
Of course a strongly typed languages should tend to have less bugs and that will save money. But saving money is only useful for those with revenue to being with.
But I see what you're getting at... if you need to whip up something quick, don't start experimenting with the "flavor of the day" language or library.
The one thing you want to avoid are communities that argue about "the best" way to do things. Even then, you can use the fruits of their labors, as long as they're willing to package it up in something that gets out of your way and lets you get work done. You just need to take the language but not the community.
I do care about my code though. I think you can write niceish code, even with a shitty language.
"It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration."
That said, all environments will be one of three:
1 Have warts. 2 Not be used. 3 Be in denial and claim to be perfect.
The GP had a point, perfection is the enemy of good. Something delivered is better than nothing.
> They just don't care.
> It's a garbage language.
I think this overly dismissive/elitist approach is part of the reason why alternatives failed. Couple that with the ridiculous claim that a developers' time does not matter.
Almost any big app you can point to that is built in PHP today was bootstrapped in this environment.
I did a lot of PHP from the late '90s up until 2008. Maybe things have changed in the intervening eight years, but I cant say I miss it.
Now I don't fret as much about unsexy tech. I do still advocate for new things when they make the team more productive, but I hope I never have to work at a place again where the latest and greatest stuff is used and people get nothing done.
My perception of the Clojure crowd is the exact opposite. They seem to be a bit too in love with the process and craft and not enough with the end results. That being said, I'd much rather code Clojure as a day job (I promise to be market focused!) than PHP. Right now I am almost all Python. There are definitely a lot of Python folks who are too much enamored with the craft, but the crowd is so big there's plenty of room for the GTD folks.
Painful to read. I've struggled with this my whole career.
Reminds me of Alistair Cockburn's seminal essay about methodologies.
Characterizing people as non-linear, first-order components in software development
Money quote:
"Problem 1. The people on the projects were not interested in learning our system.
Problem 2. They were successfully able to ignore us, and were still delivering software, anyway."
I'm overwhelmed by how rich of a statement that is.
If you consider Wordpress a success then yes PHP is successful. The thing is, a CMS isn't an interesting project to work on.
I'm going to frame these words and hang them on my desk.
If you want fast, build a static site. If you're iterating on your builds and doing something non-trivial, pick your tools carefully but don't be afraid to try new things.
As of PHP7... it actually is quicker than other languages in it's domain.
Is that acting in the best interest of your employer? or ripping your employer off? I think more like the latter.
Imagine if other professions behaved like this, like finance or legal people. But suddenly because you are an "engineer" this is acceptable? If I was your boss I would fire you immediately.
The world of difference between balancing trade-offs in technical debt, tradeoffs in long-term/short-term goals, and deliberatively sabotaging the company by leaving technical debt for other people to clean.
You are a liability to the company and its culture. And you want people like you and your language to be taken seriously? that's why nobody wants to work with people like you.
There are 3 phases:
Phase 1: Initial development - Your goal here is to find the value to your user. Any code you write here should be considered disposable. If it's not valuable to your customer, it's not worth building right... if it takes time before you know it's valuable to your customer, it's not worth your time. If you're writing it to support millions of users, and you only have 100, you're wasting your time. In phase 1 you're concerned about creating revenue, and nothing else matters. Wasting time on worrying about what is going to happen in Phase 2 might take time away from you before you reach it.
Phase 2: surge development - This happens after you've discovered some value for your user. Now the code you write is worth something. You should consider making phase 3's job easier. Proper design patterns etc. But your main concern is replacing the shitty parts from phase 1 with better code (if it's something you touch a lot) and getting it to scale for your now growing user base. You have to make strategic investments here. If you're spending your time making an ugly file that never gets touched better, you're wasting your time. If you're worried about making your code more efficient so you can support more users when another $100/month server would solve the problem, you're probably wasting your time. In phase 2 the company is still mostly worried about revenue, but you have a decent chance of making it into phase 3, so it makes sense to think about it.
Phase 3: maintenance. - In this phase, you're no longer searching for the value for the customer, but rather searching how to shore it up, how to be the best at providing it. Now tech debt is less okay. Crap quality software will lose money, so you should spend time making it bullet proof. Your revenue isn't growing like it used to, so you have to extract as much from it as you can.
No, it's acceptable precisely because you aren't an engineer.
We software engineers in the US are not bound by a formal code of ethics like more traditional engineering disciplines. We're not required to invest a certain amount of effort in the security or accessibility or maintainability implications of our work. And, most importantly, we are not legally responsible -- independent of our employers -- for defects in our product that arise from incompetence or otherwise failing to follow best practices.
So, you're wrong and your parent is right. He's not independently responsible for his work, and he has no formal ethical obligations prior to his employment contract.
Why are there no other "competitors" in this space? Why do most other languages go with the alternative route of using an event loop or daemonizing your "server" to serve up requests? I can understand why Node.js does it (otherwise the async nature would just be an annoyance for no gain), but why haven't there been any other server-side languages that not only work well like this, but actively target it?
It seems like it would be easier for everyone involved. You wouldn't need much of a GC when the process is killed every time, you don't need to worry about async IO or multi-threading or catching errors or any of the other annoyances that come with most of the traditional "event loop" way of doing things.
So what's the catch?
There are. Any language that supports either fastcgi, or runs as an apache plugin (or similar) functions in the "each request starts new" space. There's certainly others, but Python and Perl are both good examples.
Starting new with each request does, of course, mean lots of re-work that shouldn't have to be done with each request. It does initially keep complexity down, but at scale, the applications I've worked with have to use a shared cache (like acpu) to avoid that rework and meet performance goals.
I know it can result in a lot of "extra work", but I really feel like most of the pain of that could be abstracted away by the runtime.
Nginx/apache setup a PHP process before the request comes in, so why couldn't you expose that point to your language and let the programming language do work before that point, even "snapshot"ing it to avoid re-doing that work for each request?
It just seems like there are better ways of solving this problem, because an event loop is such a "hammer" solution to the problem.
There's actually work being done to build PHP frameworks that get around this with ReactPHP, ZeroMQ, Photon, etc. Essentially this is what HHVM does as well, by at least keeping your compiled bytecodes in memory (similar to APC/eAccelarator/ZendOptimizer, etc).
See: http://reactphp.org http://www.photon-project.com https://gnugat.github.io/2016/04/13/super-speed-sf-react-php...
Even the idea of an alternative runtime for PHP (ala HHVM) is nothing new: http://quercus.caucho.com
So? If it takes < 1ms, what's the harm? And opcode cache comes out of the box and most PHP DB drivers can use connection pooling.
We serve most of our requests in < 10ms, and we're not even on PHP7 yet.
All the magic you ever need can be dynamically created in __get, __set and __call. It works, it works well, and it makes not only reasoning, but also deployment an order of magnitude simpler.
>Code paths, auto-loaders, database connections, config files, etc.
Use a single code path, a single autoloader and a single database connection. Cache the opcodes of stuff you load. Write config files and templates in pure PHP, so they're cached as well. Done.
I've never, ever had problems with bringing PHP page generation time below .1 seconds. Usually it took something like .03 seconds on crappy hardware. And that was without extensive caching of DB results or anything else that's particularly clever.
Do you most of those need to happen at all, ever? In my mind, auto-loader is a sign that nobody knows what's being loaded (if they did, they would just require it). Requires should be full pathed (because have you seen what happens when you search the include path). Mysql_pconnect has been doing connection pooling for a long time, mysqli supports it too (so yes, you do need to connect sometimes), anyway, if you're loading a framwork, loading that probably takes longer than connecting to a mysql server in the same colo.
Or that, you know. There is an extremely powerful language feature and the developers are taking advantage of it.
Well, it depends on how it's implemented, and how pedantic someone gets about what "shared nothing" means.
There is a long history of unix daemons that initialize, listen(), and then fork off a child process whenever a client connects. The child does all the work and the parent goes back to listening. You can do the "up front" work once and then each child can only modify their copy of the data, preventing it from interfering with the next request.
> It seems like it would be easier for everyone involved. You wouldn't need much of a GC when the process is killed every time, you don't need to worry about async IO or multi-threading or catching errors or any of the other annoyances that come with most of the traditional "event loop" way of doing things.
Firing up a new process (or even a new thread) for each request is very expensive--much more so than a generational GC. Async IO also mitigates this (why have 10K parked threads consuming memory all your memory if all of them are stalled, waiting for database)? Services that spawn a thread for each request run into the C10K problem--they can only serve 10K simultaneous clients. Regardless of your concurrency model, you can't ignore errors--you still need to dispatch the right status codes and error information (not to mention logging, etc).
You should check out Go. You write concurrent code and the runtime effectively manages a thread pool under the covers so you get all of the performance benefits of async programming with the developer-friendliness of synchronous programming. In the case of a web app, you just need to write your request handlers--the web server manages the request concurrency for you, and the language's runtime manages the parallelism.
True, but I'm not aware of any notable language that did it differently in the mid 1990's when PHP was rolled out. PHP does not spawn a new OS process per request these days. It does spawn a new interpreter, but not a new OS process. Combined with the now bundled opcache, the re-work per request is limited to the developer's own initialization code if they don't choose to use a user-space shared cache.
Which isn't what PHP does, fwiw.
And you can also set up Ruby, Python, Rust, Haskell, Java, etc to create a new interpreter/vm/whatever for every request. All of those languages have libraries to support CGI. Using the same OS process but restarting the interpreter/vm will be a bit more complex, but absolutely possible. You can even implement the "every file is an entry point" approach for at least Python and Ruby.
The difference is what is the intended use for each platform. E.g. creating a new OS process, loading the PHP interpreter, bootstrapping Wordpress, getting some data from the DB and rendering a page is possible under 600ms while creating a new OS process, loading the CPython, bootstrapping Django, getting some data from the DB and rendering a page will easily take you 4 seconds. This is because Django developers didn't expect you'll be doing that, so they put a lot of stuff in the initialization step (system checks, creating db connections, setting up logging, ...).
This was never actually an asset. Startup times were huge, lack of shared state meant extra requests to database servers (and to memcache instances to avoid database round trips) to get the same data per-request. Each request got longer and a given page or api call might issue many duplicate requests in a short period of time.
Plus since PHP doesn't have viable threading or async (definitely didn't at the time) each memcache or sql request had to be synchronous, resulting in even more wasted time. At the very least memcache had good support for batch operations so we could manually batch our queries.
Overall though this is not an asset. It's only the 'best' part of PHP if you don't want to think about writing good software that manages shared state.
To be fair, many applications don't actually benefit from being good code, so PHP is probably a good fit for those.
Here is an example in C: https://www.cs.tut.fi/~jkorpela/forms/cgic.html
Php was born out of trying to reduce a lot of that cruft and blending code and html output easily. And that's what initially made it a winner.
Which should be near 0 if you can be bothered to enable OPcache in php.ini. Not only parsing/disk reading but also bytecode generation are bypassed.
A bit tangential, but I find myself disliking it too, for no good reason that I can think of.
Perhaps it's something of a crutch in that it's really "I like it more, but 'reason' sounds better" ? Not sure that's quite it, either, as in the above case with a "new everything per request", it's certainly true that it's easier to think about what's happening.
The phrase has a high correlation with subjects that are themselves highly correlated with smug proponents; functional programming is one of the greater ones of these.
Personally I like the phrase. Then again I self-identify as a (non-smug) SmugLispWeenie[2] so of course I like it.
[1] https://www.infoq.com/presentations/Simple-Made-Easy [2] http://web.archive.org/web/20160709054130/http://c2.com/cgi/...
You can get the same reasoning benefits in pretty much any language by just not using any global variables. Yes, you're still running a framework/server with internal state, but with PHP you've got the same "issue" with Apache/Nginx.
You are running it from RAM. PHP's OPcache, and HHVM, will both compile the code only once (well, HHVM will compile it multiple times due to JIT, but it only touches the disk once) and cache it.
Define "very". Because for me it's more like "a few hundred microseconds per request".
And even if you cache everything, you still have the code necessary to setup the runtime environment of you application which runs on every request and does the same thing.
But still, I do actually like that model and it does have many advantages for development. But it's really hard to work in PHP, the language, after using something better.
For the conversion to bytecode, that is what apc is for.
But also, you don't typically use lambda to serve pages or a full application, more commonly it's used for specific processing tasks, individual endpoints, and generally code that can run standalone.
Other languages, whether directly or indirectly manage cleanup via GC or recycle processes, like UWSGI for Python.
I also don't find any particular benefits over other languages with "reasoning about". As a PHP application grows and a team restructures it into something more mature it ends up looking the same minus the event loop (which just lives somewhere else).
Yes, you do. You'd be surprised how easily memory balloons out of control unless you regularly run a GC. Log minor collections sometime in Java or JS engines if you don't believe me…
Even worse, if you don't run GC regularly, you will suffer terrible locality as execution continually grows the heap (not to mention the overhead of continually requesting free pages from the OS).
It's not an insane idea - CGI worked exactly like this, as do most command-line shells. And the overhead is often less than most people expect, since most pages are COWed on fork() and the files it touches will likely be in the filesystem cache. Still, I think people found that the overhead from process creation (and in particular, keeping all those processes around & task-switching them while they make DB/network/filesystem calls) was greater than that from GC, and so most frameworks - PHP included, these days! - use a more lightweight mechanism.
Not that I feel cgi is the most efficient way to handle requests... but not needing the complexity of GC could be one advantage of that approach...
Any recommended places to start with?
So this process-per-request thing is not exclusively a Php thing.
About 2-3 orders of magnitude in performance. That’s the catch.
And it’s the reason why even with PHP you use things as opcaches, cache database results in external daemons, you use process pools with fastcgi instead of actually creating new processes, etc.
And hacking those things on top of PHP make your program even worse to reason about than just using a daemonized system with actor framework.
> And it’s the reason why even with PHP you use things as opcaches, cache database results in external daemons
You make it sound as if the idea of caching was invented by PHP programmers to address language deficiencies. Nothing can be further from the truth. Everybody uses caches, because it's faster. If you don't use DB cache, there's no way in the universe you can make you app fast under any significant load.
> And hacking those things on top of PHP make your program even worse to reason about
You have very strange view of performance design if you think using caches is "hacking something on top" and has to be avoided.
> than just using a daemonized system with actor framework.
This looks like a complete non-sequitur - you could use actor framework and still use all the things described above, and do it in PHP, and thousands of people do exactly that. On not in PHP, if you'd like - this pattern is completely orthogonal to the language used.
People go to a lot of trouble to optimize the front end system, but tie it all to the same database that bottlenecks well before the web server. There are certainly times where PHP or CGI aren't fast enough for the job, but I think people tend to unfairly blame them in situations where the underlying problem is more systematic.
If you need to process thousands of requests per second per thread then don't use PHP, but that's a rare situation. I wouldn't build RTC in PHP. But web or enterprise applications, which are by far more common, don't really suffer that issue.
And pretty much everyone caches database results...
Compared to the other offerings, it's on par or faster (Python and Ruby really have a lot to be desired). You're talking about an actor framework, which is more performant at a cost of using that model and the myriad of issues with managing a more complicated system. The market favors simplicity and less sophisticated developers, in most projects.
A rewrite I worked on, from PHP to C++, had an improvement of 20 times better performance.
That's only one (1) order of magnitude.
The catch are couple.
First Concurrency is _hard_ and relying on the OS scheduler would have been really har don ressource until recently, which is why nearly noone did it.
That used ot be a wart of php, only hidden by Moore's Law and recent work on OS schedulers.
But yeah. Erlang do this since the 80s
Actually I have never seen that this was a problem in practice with the application server model. I therefore don't think this is a relevant argument.
You can do the exact same thing with any language that supports CGI. You can compile a Go binary, put it on an Apache server and you'll get the "shared nothing lifecycle" just like PHP.
Isn't there a downside to that? If you want to do multi-threading, you can't just do `ThreadPool.StartNew(() => doSomething())`. You're SOL.
It’s really interesting, last time I worked with PHP was a few years ago, then recently I wrote something in PHP 7, and it is a lot safer.
(But still no compile time type checking because there is no compile time).
That said, PHP is really good at what it does - providing a framework and environment for serving web requests efficiently and easily. I find developing in it very fluid once you know how to avoid the warts. A lot of the flak that PHP receives as a language revolves around the fact that it doesn't actively discourage developers from doing bad things, and sometimes the language itself does some crazy stuff (as shown in the article with the divide-by-zero behavior). I think this is a huge shortcoming of the language, especially as code bases and teams grow and your organization needs to depend on the language more and more for safety. That said, I still don't hate working with it. Sometimes I rather enjoy how quickly I can develop in PHP, and how reliable it can be if you know how to operate it.
I think in all, it was a bit of a slog to get to the point where I am with PHP today - to the point where I understand its strengths and flaws, but ultimately I think it does have a place in modern webapp development. I think Hack and HHVM are excellent spiritual successors to what PHP tried to (is trying to?) accomplish, and that they do a great job of hiding or eliminating some of the warts of their parent language.
Kudos to the Slack team for being pragmatic about their approach to the technology, and hey again to all of my former colleagues working there!
I've read a lot of PHP hate over the years, but I've found working with it in practice to be decidedly...not bad. Perhaps the codebase I inherited is better than most. But I've had to make some fairly major updates, and they've proven to be far less painful than I had expected based on the amount of PHP attacks I'd read online.
Maybe the snobbery toward PHP is a good thing? There are some really big PHP-based communities out there, Wordpress being probably the largest. And in these communities, there appears to be a large demand for paid consulting and plugins. Sure, there's a ton of competition on the low end, but it's an area where a really great developer could stand out from the crowd and do very well financially, especially for more complex consulting and dev work since so many good developers turn their noses up at PHP.
The Wordpress codebase [plugin api included], though, is utter garbage.
[1] http://www.phpsadness.com/
[2] http://php.net/manual/en/language.expressions.php
[3] https://www.mail-archive.com/internals@lists.php.net/msg7196... (yes, i asked for this in 2014)
It was consistent with the thing it inherited most of it's syntax from so that makes it inconsistent?
> The devs are ultra-conservative and stubborn to cause BC even at major version bumps (like the forever-incorrect ternary associativity [2][3])
You shouldn't be judging the way operators work in one language with the way they work in others. Is lisp inherently bad since it's operators are prefix and not infix? No I'd say not, it's just different.
On the other hand, the PHP devs changing the ternary would cause major problems for anything that uses it. The most the PHP devs have done is deprecate methods and add features. That's great. I think that changing something, that has been there since the beginning, to a new behavior is stupid. Much much much worse then having ternary work backwards.
> The Wordpress codebase [plugin api included], though, is utter garbage.
Yes, yes it is. That's not the language's fault.
Well, breaking backwards-compatibility comes at a cost. Avoiding another PHP 4/5 or Python 2/3 situation is the goal. It doesn't mean nothing gets changed: PHP 7 has a long list of backwards-compatibility breaks.
I've always heard this and never actually used Wordpress myself. Has anyone ever studied WHY its garbage? and how did it get to that state? is it getting better or are the latest additions and changes still garbage code?
I'm going to guess they picked PHP because they knew PHP and not because of the nice reasons mentioned in the article. That is the article should be "why slack is sticking with PHP".
Almost all the major languages are actually (despite lots of HN debate and arguments) fairly good choice for developing not because the major languages are expressive/powerful but because they have very very mature tools (e.g. Java sucks but the JVM and its tools are very mature) and lots of people who know it.
Basically you could write a plethora of articles with "Taking MAJOR_BORING_LANGUAGE Seriously".
For example I'm responsible for choosing Java for my companies startup. Java historically is not a very productive language to pump something out but in recent years it has vastly improved... regardless I chose Java because thats what I knew at the time and I would pick it (or some other JVM language) again. And I could rattle off whole bunch of reasons why the JVM still kicks butt but the reality is I am biased because of my familiarity.
If anyone wants to come off like a 'serious' programmer, all they need to do is denounce PHP as a horrible aberration, a frankenstein of a language. Most don't even know about the changes in the language over the last decade, they just hate it to stay inline with their peers.
However, those opinions dont line up with the facts. PHP goes beyond semantics of language, it's a complete service for delivering dynamic HTML from the server. Why is it so successful? It is one of the most robust, well supported, battle tested languages to appear in the last 15 years. Its support is guaranteed on any hosting platform or cloud solution available. It has a large array of libraries capable of integrating with most any service whether that be databases, web apis etc. It has the ability to scale for high demand, as demonstrated by the many large corps that use it.
If you want to rip on PHP because it's cool, I think you're simply shooting yourself in the foot and ignoring a tool capable of performing almost any task you would require of it on the server side.
This cannot lead to real conversations or good software. There are far too many naysayers always eager to jump in with their 2 bits of negativity with the same cliched talk points and links most of whom I am sure would never be seen near php and may not even have used it.
The criticism goes silent when HN favourites like Slack show up on discussion. Ignoring the sheer number of high traffic websites and successful startups using PHP is just another way to deny it its due.
Most PHP apps are a breeze to install and use compared to just about any Ruby or Node app. Try installing Discourse to understand just how user hostile it has become. The respect for users and simplicity comes through in PHP. NPM and Ruby with their dependency hell expect a full dev environment even on user machines and nobody thinks this is ridiculous. There is no denying PHP warts but Node, Ruby and Python I think have their fair share of issues.
I really do like Python but for a web project that needs to scale and not get mired in other issues I would choose PHP every single time. For a library or SAAS app maybe, but for an installable app I would never expose users to the Ruby or Node ecosystem.
While i do not think PHP is a perfect programing language. There is one think i LOVE about PHP, it is that the PHP "community's" default way of documenting code behavior is to make a small example.
When i read most other languages documentation i read it. Then i need to make a small test to verify that i understood it.
All those tests takes a long time to make and i have to make them over and over again, every time i forget the way a function behaves.
It's harder still when you're trying to en/decrypt data from multiple programming languages... Java is particularly painful as well, since a lot of the things that are "standard" are abstracted behind class structures with naming that differs from the standards.
I must say that PHP 7 is a great language nowadays. Most of the modern concepts are baked into a language or are about to be developed.
At some point, I wish Hack and PHP merge into a single language in the future, somewhat similar to what happened to Node and iojs. I'm not sure if Hack is going to be around in 5 years, but I'm pretty confident about PHP.
I'd definitely love to see more articles about Hack and people's experience with using it in production.
Most of the hate for PHP comes from the PHP 4 days, but we are well past that and charging ahead with featureful yearly releases.
>First, state. Every web request starts from a completely blank slate.
Except for, you know, when you don't want to reinitialize everything everytime someone makes a new request. There are tons of things that you only need to run once.
>I claim that PHP’s simpler “think; edit; reload the page” cycle makes developers more productive. Over the course of a long and complex software project’s life cycle, these productivity gains compound.
I cannot disagree enough with the conclusion he draws from the quick feedback loop in PHP. I do PHP in my day job, because that's what our codebase is in, but recently I finally got the opportunity to use Haskell for a side project. The feedback-loop might be slower (honestly not by much, automatic reloading is a thing in almost any framework), but I'm a zillion times more confident in my code, because you are able to encode so much logic in the type system, meaning the compiler will catch whatever. Contrast this with PHP, where I'd almost have to visit every branch of code when I alter something because of it's many weird behaviours. Particularly when refactoring code, which you often end up doing while hasing something out.
Also, PHP works at a quite coarse granularity of concurrency. A thread per web request only? As soon as you want to do something more advanced, you are forced out into the many patchwork solutions (wanna do async? queue that shit).
Sure, a lot of people have done a lot of quite cool projects in PHP, but I would much more benefit that to the lower barrier to entry - heck PHP was my first language and I made a CMS from scratch without even knowing much of what I was doing.
That said, it has come a long way, and something like HHVM/Hack definitely helps a bunch! I just think the pros in this blog post are quite weird and IMHO incorrect.
</rant>
I mean, you're not reinitializing it, and it's not exactly slow. And when your application starts scaling across many instances, many zones, many servers, you can have more faith that each request runs independently and there are no runaway processes to worry about on a single one of your random servers somewhere.
> where I'd almost have to visit every branch of code when I alter something because of it's many weird behaviours
I'm not really sure what you mean by that. Write a method, write tests for that method. Just because PHP has weird type coercion issues doesn't mean you can't be diligent about the types that you use. And of course tools like PhpStorm understand docblocks, annotations and PHP types and classes and basically does the same thing that a compiler does, it'll show you big honking type errors if you ask it to, it'll even stop you from committing broken code if you use that option.
> Sure, a lot of people have done a lot of quite cool projects in PHP, but I would much more benefit that to the lower barrier to entry
I don't know about that. Low barrier to entry gets you a lot of crummy projects. In my experience PHP is a lot easier to manage and maintain in production, and that's a huge advantage to companies and products with small teams.
It's just as easy to scale with other languages, you would keep the data that needs to be persisted in a DB. The benefit comes from things that does not need to be persisted, like resource pooling, memoization, config loading etc.
> > where I'd almost have to visit every branch of code when I alter something because of it's many weird behaviours
>Write a method, write tests for that method
Exactly, I need to write tests for things that are trivially verifiable by a compiler. And I'm not just talking about type coercion (which is a bad thing), but also missing function parameters, wrong parameters, missing initialization of variables etc etc. These are runtime errors and you either have to write tests to catch them (hence visit very code block) or manually try and reach them.
Some IDEs, like PHPStorm, can you get pretty far though.
>Low barrier to entry gets you a lot of crummy projects
As someone else mentioned in another comment, 1% of PHP projects succeeding is still a lot more than 20% of Haskell projects.
>PHP is a lot easier to manage and maintain in production
Except for when you need to scale. Varnish, memcache, php-fpm, redis, what-have-you are basically mandatory for a PHP site to really run performant, adding quite an overhead to any production setup you'll get into.
Business logic: Don't write it in PHP. Write it in PostgreSQL.
Authentication: Don't write it in PHP. Use Apache 2.4's mod_auth_form. Replace hundreds of lines of PHP code with a few lines of Apache config. When it gets to your PHP script, all that's left to do is read $_SERVER['REMOTE_USER'].
Authorization: Don't write it in PHP. Use one of Apache's modules (LDAP, DB, or even file) or if possible make your users all very restricted database users and use database permissions more.
Don't need a database? Then why not handle it all on client-side JavaScript?
I'll admit that my advice fits well with CRUD web apps. If you're doing something else, PHP may be gross.
But really, my goal in programming (don't always reach it) is for PHP to just make a simple database call and wrap the result in HTML. If you're doing 123 == '123foo', can you move that up into the database or down into the browser? If you're writing elaborate class hierarchies in PHP, I think you're doing too much in PHP. I write a few functions, if needed, but mostly move all data processing to the database or browser.
I was right it was: https://www.infoq.com/presentations/php-history but the author is the same person.
It is a good speech and I've been developing in php for years, written a blog post (http://sucky.ninja/leaving-php-is-too-expensive/) about it but I do no longer use php for my backends.
I've whole-heartedly switched to ASP.NET since my productivity is increased with it and I can actually use the language (C#) for other things. I would've agreed with the author a couple of years ago but with Azure, AWS and other cloud services it is simply no longer true that php gives developers a quicker feedback loop. I can setup a node server with gulp and start working in 10 minutes or I can start a new ASP.NET project and deploy to production right after the project creation has completed. With php I still have to setup a virtual machine etc etc.
I would not go back, even if it is cheaper.
So if other languages are just as easy to deploy, what does PHP bring to the table?
Even if php has it´s nice things it is still not that great of a language.
"PHP is garbage language!", "PHP is a shitty language!"
That is the antiquated view of course. The old days.
Now with Laravel and PHP7 it is a pleasure to use.
I'd go further.
Working in Laravel is BETTER than ROR IMHO.
rails + unicorn/passenger v/s apache + mod_php.
> First, state. Every web request starts from a completely blank slate.
> Second, concurrency. An individual web request runs in a single PHP thread.
> Finally, the fact that PHP programs operate at a request level
Isn't this just "virtues of Apache modules"?
There's mod_python, mod_perl, and mod_ruby. Are state, concurrency, and global requests virtues of these languages too?
---
Even if you do somehow convince me that these virtues are specific to PHP, you can't convince me it does it well. Hence, MaxRequestsPerChild.
To quote Radmus Lerdorf,
> The real programmers will say "Yeah it works but you're leaking memory everywhere. Perhaps we should fix that." I’ll just restart Apache every 10 requests.
Clean slate, my eye.
They're cattle not pets. (/semi-sarcastic)
Also, most folks serve PHP applications in production under PHP-FPM/FastCGI.
Now I look back; I see the projects which have technical debt were flawed in design and did not get maintenance they needed. Most of them did not get traction to the point where scalability issue came into the picture.
So this year, we started moving that 5 % non-PHP projects to PHP counterparts. Again, we are miles away from any real-world scalability issue, but at least we are now able to maintain projects as we have a large PHP team.
At a small to mid-size organization level, it is more important to use one language for all projects.
I believe technical debt is not related to the choice of language but anticipating direction a project might take and picking up right design patterns to support that.
Which programming language is better is a highly overrated question!
I wish I had learned this few year ago.
I recently finished up a fairly complex web app that uses PHP 7 for the back-end. Took me under 2 weeks to develop partly because I was able to leverage a lot of stable and well supported libraries through Packagist. It brought in over $4k its first month. Not bad for 2 weeks worth of work. It would have been hard to accomplish the same thing that quickly leveraging Node or Python (I use both) at lease for this app.
Does anyone have a good example of an open-source PHP project that will enlighten me?
After reading this thread, is there even a proper way to measure how good a language is (trade-offs, benefits down the road)? Having done web stuff in PHP and Python I think both are terrible. So, how would a programmer trying to avoid his own biases and anecdotes find what tools are right for each job? Maybe I didn't "liked" PHP and Python because I'm a terrible programmer. Or maybe I only worked with awful teams.
Is there any science involved or should I make my decisions based in what blog post I read that week? How can I actually trust the opinion of companies/engineers if they are so invested in that tech? Who would admit that after investing millions on it they didn't actually think it was worth it? There's no way that I'll be able to have deep knowledge about all the languages that are out there.
The sad thing is that I end it up choosing whatever is popular and half sane because not finding (updated/well-maintained) libs or tools you need is worse than picking a niche language that might do the job better.
Nope.
I mean.
They're all Turning Complete (except for the ones that deliberately aren't), and they're often good at expressing different types of problems.
So depends what you're trying to do.
Trouble is, it so often turns out you didn't really know what you were trying to do till you were nearly done doing it and then you're stuck with what you picked.
PHP is pretty good for building website prototypes, and can now handle the scale as they grow too really.
But "Good" depends on what you're trying to do, and what tools you already are running anyway.
Is there a way to measure how good a spanner is compared to a hammer?
[1] https://www.amazon.com/Concepts-Techniques-Models-Computer-P...
You:
<!-- api.php -->
{
<?php
mysql_connect("host", "pass"); mysql_select_db("users");
$uid = $_GET[ "uid" ];
$res = mysql_query( "select * from users where uid = $uid" );
$ar = mysql_fetch_assoc( $res );
echo "name: " . $ar["name"] . ","; echo "location: " . $ar["location"];
?>
}
<!-- end of api.php -->
Just call it http://domain.com/api.php?uid=USER_ID
( Yeah I know you want to scream and say all the things about this code, but this is kind of code you would encounter with PHP, most of the time it's more horrifying than this one. )
People use it PHP for this reason, If you want to make same functionality in another language you need to setup an app and all the necessary things that protect you from garbage, some obvious security issues and bugs, not a single file like this. It's so easy and so wrong, it should be illegal to do this. Create a file and put it into directory and call it from your browser. You don't have to know anything about web or web servers and stuff. You just make shit by copying and pasting from internet, that's why Facebook made by PHP and now there are whole teams who are trying to protect company from PHP horrors. (They made a PHP VM, bunch of software to analyze PHP and optimize it etc. )
Just don't try to justify PHP, do not defend it. It's shit and you know it, accept it and move on.
(Note: do you remember Facebook's profile.php pages, they are still exists you can call it just like old times profile.php?id=YOUR_ID, yeah it's a shit once you get infected you're not gonna get out of it completely. Even if you can, it leaves traces on you just like profile.php URL's
Regardless of their findings I wouldn't recommend anyone learn PHP if starting out.
This is bad advice.
If you are a new programmer starting out, first of all you should learn a few languages, not just one, but also, why would you not want to learn one of the most popular and prolific languages in the industry you are trying to enter?
If you want to work in the web world, not knowing PHP will close lots of potential doors. They may not be the coolest of the cool but not everyone has the luxury of being that picky when looking for work.
Of course if you are an exceptional developer and/or you live in one of the insular startup hubs (SF, NYC, etc), then you can get away with being picky and sticking to the bleeding edge or the du-jour tech stacks and you'll probably get hired, but for the majority of people entering the web development world, that may not be the case, and they should be more pragmatic.
Even if you don't specialize or focus on PHP, knowing how to code in it will help you land jobs and advance your career.
And their target was people who would install Wordpress themselves on a cheap shared host.
Facebook and Wikipedia probably used PHP because many developers knew it, and the reason was... That there was many cheap shared hosting solution for their pet projects.
Not only this is no longer true (it's just as easy and cheap to host Rails, Java, Scala, or anything with cloud hosting), but the availability of cheap shared hosting is not relevant for most problems.
tl;dr:
* Wordpress couldn't have succeeded without PHP, because of a context that is no longer true today * Facebook succeeded despite using PHP, because they had the manpower to fork the language and write their own VM
It was his first PHP project.
(And why didn't Wikipedia have a visual editor until 2013, rather than 2005? Because wikitext syntax was literally defined as "whatever this series of PHP regexps does". Of small acorns, mighty oaks of technical debt can grow ...)
Anyone who claims anything even vaguely in the direction of "PHP is good 'cos Wikipedia uses it" is talking rubbish.
The implication that C is an especially strict language for type conversions is strange. C is actually one of the loosest languages for type conversions. It's even legal to do things like compare pointers to integers (though most compilers warn you)!
the "most typical" Python stack (wouldn't call it a application server) is probably built with Django where you don't reason about the Server restart, it's as fast as changing something in PHP.
P.S.: I don't use Python that much anymore. Other people would say that the thing I'm using now takes endlessly long to compile and has some wierd operators.
And the subcycles are literally "Change -> [run test | send test request]".
> Hack provides an option that no other popular member of the MPDPL family has: the ability to introduce a type system after initial development, and only in the parts of the system where the value exceeds the cost.
Python 3 allows you to do that, too: https://docs.python.org/3/library/typing.html
Javascript has Typescript and Flow, both of which are very popular and allow you to gradually transition.
this is certainly what got me started with PHP and what makes its so easy for beginners
I ran into this problem today with some code by a programmer who should have known better. The problem is not with PHP, it's with programmers who learn one version and then don't keep up and change as the language evolves and improves (ain't nobody got time for that.) One guy I work with is still programming PHP like it's year 2000. It's maddening. PHP7 is a very nice language. People decided JavaScript was cool after "The Good Parts" came out. The same is true for PHP. If you learned PHP3 in high school and are still banging out code like you did then, you're the problem, not the language.
Personally I wouldn't choose it but, for a larger company, if you already have engineers that know it - and trust me many will - it's not a bad choice.
This is especially true if you are just serving a simple website for a product or service, even basic e-commerce. 90% of websites out there don't need Rails, or Python, or Go, or Node.
He's obviously a big fan of the language, and surely had a big hand in influencing what technology would be chosen very early on.
PHP can be like playing with dynamite. If you have an explosives expert on site (or Cal Henderson), you can get a helluva lot done with PHP in a very short amount of time.
None of them matter in isolation. If you have a team of people who likes to think dynamic, functionally and meta-linguistically, just pick the best Lisp-family language for your needs. For another team who prefers to think dynamic, functionally, with actors and pattern-matching, pick Erlang or Elixir. Someone who likes to think pragmatically, likes obviousness and simple static typing should probably pick Go if he's also "minimalistic" or Java otherwise. For a "move fast and break things + fuck this functional programming bullshit" thinking team, pick the best version of PHP (Hack & HHVM) etc. Want "move fast and break things + ok with event-driven + some sprinkle of functional programming goodness", then use Nodejs.
For example, for "move fast and break shit" prototype development I pick Nodejs over PHP because my mind "works functionally" and every attempt at writing functional code in PHP is pure pain.
There is a reason why there are so many languages: people think very very very differently from one another, but at the same time they think similarly enough that they can gather in "tribes" around certain technologies and idea!
Of course, this is not a post about how good or bad PHP is/was. It's just a matter of personal preference at the end of the day. Your favorite language is the one you feel you're the most productive in and says a lot more about you and your experience/background than the language itself.
That said, nobody will ever convince my that the style of structureless, start-at-the-top, run-to-the-bottom monolithic PHP pages has any merit at all for real apps. I have seen many projects fail, or slowly mire themselves, by creating these monstrosities, with the opening <html> tag 1200 lines down the file. But I assume these days that's not common.
The second disadvantage, passing by reference vs. by value, honestly can or cannot be confusing, depending on which other languages you are accustomed to. So I would say it is a debatable point.
The third point, the language being failure-adverse, is a choice made by design, this is also a debatable point, but it's in line with the fact that PHP was created as a utilitarian language as Lerdorf explained numerous times, e.g. here https://www.youtube.com/watch?v=anr7DQnMMs0
The last point, inconsistencies in the standard library, is obviously true but I would say it is very common in languages that have been around long enough to have subsequent approaches layered in the standard library. Some languages resolve this by making breaking changes and keeping consistency (think Python 2 vs Python 3), some others just show their age by having libraries that were developed at different point in time (Perl, R and Java come to mind), this is also explained by Lerdorf in the video linked above.
However, I disagree that "other languages do not work like that thus are not as easy to test". You can implement this in any way you like in any other language. You can implement your webserver by forking a new process at every call. You can even use a worker that communicates to a different hot-swappable process. It can efficient as you want - copying the whole data around, sending file descriptors, etc. The alternatives are endless.
PHP may be "interpreted and hot-swappable" by default, but that's an accident from it's design and it only works like that - if you try to use it as a long-running process, you'll run into a lot of issues. It's also terribly inefficient - have you ever developed a web interface for an embedded platform? A really embedded one, like 32MB of memory, shared with the application itself?
I guess in the end it boils down to the duct tape analogy: it's terribly fast to prototype something with duct tape and scraps and you can join a multitude of materials in a very simple way - just put everything in place and cover with enough tape to hold it together.
Surely, it works.. but that's about it.
The quality of open-source libraries in the ecosystem is also pretty below what I've come to expect from other languages, and then half of them are c-lang PHP hybrids that are more difficult to manage, update, and install.
I think the author failed to mention the downsides of no long-running processes either. Shelling out to e.g. memcached for configuration setup (especially when memcached might not live locally) isn't particularly fun. Not to mention this has made it difficult to integrate into some useful things, like GRPC[http://www.grpc.io/] which can't use PHP as a server as of yet.
Then there are all sorts of random deployment gotchas, like proper opcache configuration.
PHP is a pretty wart-filled language. It's usable, but I wouldn't make it my first choice in any situation, given a choice.
Edit: I commented on this post before the OP edited the original with a longer form explanation. Originally it just said he didn't like the debugging and left it at that.
[0] https://www.infoq.com/presentations/php-history [1] https://news.ycombinator.com/item?id=7054294
While it doesn't matter that much at the end of the day, php is slow compared to java. A language which has so much hidden potential performance (from 5.6 to 7) can't be that good.
Also a lot of stuff i was used to in java is now also how php developer write code but with a language which doesn't support it properly. Annotations for example.
The worst thing was the type annotations in comments. Why do you write type annotations in your php comments? Because otherwise your ide can't protect you from those errors. and it doesn't provide you with proper code completion.
When you use tomcat and basic servlets or spring, you can write code quick and easy without any problems. Not sure why you wanna would use php.
Tooling is much better (IDE support, Profiler support) and Debugging is much better (simple to connect, can drop frames) and yes java has hot code replacement.
I can change the code while i'm debugging it and than drop the frame and test it again without reloading anything.
And at the end of the day you do know a language which you can use for android, server, games, desktop clients and it is cross platform out of the box.
For decades people have been complaining about Php, and how afwul it is, yet still, for decades successful projects have raised (and still do) having Php as its core, just today there 2 posts on the front-page about big companies (Slack, Dailymotion) talking about their Php codebase...
The argument that due the huge volume of programmers using it, it is "bound to" return a few success cases here and there is BS... if that were true we would be flooded about news about how X and Y company succeed "thanks to" using Python, Java or whatever language you deem as "superior", but that doesn't happen... because companies don't suceed "in spite of" Php, they suceed "with" Php, in the same way companies don't suceed "thanks to" X or Y language but "with" them.
When people set to built a piece of sotware they don't have in mind "I wan't to build the most technically perfect code base" or "I want to build the fastest piece of software" because nobody writes software for the sake of it, everyone has a goal... they want to build "a messaging app for teams" or a "video-sharing website" and the best programming language for that, is whichever enables them to do so on the way they need it, with the resources they have, and within the timeframe they set.
And rant as much as you wish, but Php remains king about doing exactly that "enabling people".
But look at the way modern php developers work, in PHP7 with frameworks like Laravel, Symfony, and even Drupal 8. Modern PHP is a pleasure to work with.
The reality is these (above) and many other good languages/frameworks exist out there for building web apps today. we live in the time with a ton of choice, and the rest is in our hands.
I for one love the new .NET Core, but I am a little biased being a long-time .NET developer and a Microsoft employee as of late.
So if the first language/stack is less respected, it makes it easier to sell that rewrite to non-technical/management. Thus PHP is a great choice for the first stack.
The one huge trap here is if the second team isn't experienced enough in the holy grail (next) stack. I've seen that and been relieved to walk away from those projects/companies.
Progressively adding types:
This isn't PHP it's hack. How is this different than typescript or flow?
Edit/refresh vs edit/restart server.
It seems like it's been several years that there have been things like meteor or webpack that make iteration super fast on JavaScript. Is that iteration slower than PHP?
JavaScript and Python both have systems that allow you to do this: JavaScript has the Google Closure Compiler, and, more recently, TypeScript. Python has a number of projects that use a common syntax [1], including PyChecker.
I say this not to "well, actually" the post, but just to be a gradual typing cheerleader. It's great! We should all be using it! All the time! Please!
There's a way to make Apache fork after some code has already been run, but boy howdy if you don't do that and love those mega-frameworks.
- First of, it is the language i have the most experience with. It would have been stupid to start with some new fancy stuff that would postpone our MVP or getting market/idea/product validation.
Apart from that...
- PHP allows you to write good code, it just does not force you to do it. Means if i need to prototype something really fast i can do so. At stomt we are really focused on writing SOLID code.
- PHP evolves great and became really fast in the last years.
- Economically it is cheaper to find PHP developers than developers in most other languages. And if you have a nice and clean software architecture in place, it is easy to also get more unexperienced developers to write good code.
The main advantages of PHP are ease of deployment (no build required, just upload your files and go, use a shared web hosting or a cheap VPS) and a fast dev cycle (edit/refresh the page.) It's also simple to work with for web designers who don't have a lot of back-end knowledge. They can edit your templates and see results instantly.
For anything with complex business logic, background processing, etc. it's absolutely the wrong choice. However, for basic web apps, when combined with a good framework (such as Laravel), it is fast and productive.
NPM is another great/horrible thing in JS... people get hung up on the size of some packages, it's worth noting that a lot of that size doesn't go into your application, mainly because those packaging don't always know enough to exclude their samples, tests and documentation from the module as packaged in npm. Which is a mixed blessing.
You do get a lot of file bloat as it's not pre-build/bundled in npm (usually), and as such there is a lot of file-system access at startup (SSD strongly encouraged).
Through all its' warts, I'd still take it over almost everything else I've ever worked with.
I've seen Hack used in a multi-tens-of-MLOC codebase to gradually insert types. It made huge differences in the kinds of changes that were possible; you can, e.g., rename a class or method, or change the order of its arguments, with confidence comparable to that in a C++ codebase. Most developers hack-ified everything they could get their hands on, and did all new work in Hack, without any external encouragement.
In terms of Hack as a language, it's very similar to the JavaScript->TypeScript relationship. It's still mostly PHP, but it doesn't quite get the new PHP features as quickly, and there is the chance that there could be incompatibilities in the future which could cause new PHP code to start looking and acting differently than Hack code.
The XHP plugin[0] (which you can include as a Composer dependency, but you have to be able to run Composer directly under the HHVM daemon and not PHP) allows XML to act like a first-class citizen. No more interpolating between HTML strings and having to escape all of your variables, you can now just do
echo <b>{$possibly_evil}</b>;
and it just works (and auto-escapes.) You can even extend the XML root object to create your own tags[1]. Combined with Hack's native autoloader[2] (which allows whitelisting constants, functions, tags and types) Hack provides a lot of the features PHP developers will find standard in most templating frameworks, without the overhead of the actual framework.Another benefit (possibly) is that improperly formatted XML will break with an error, so it's guaranteed that if your document renders, it's correct.
[0]https://docs.hhvm.com/hack/XHP/introduction
[1]https://coderwall.com/p/3leegq/getting-stuck-in-with-xhp
[2]https://docs.hhvm.com/hack/other-features/autoloading
Hack allows generics, type hinting and aliasing[3-5]. These only apply when running the typechecker, however, when the code is running, everything decays to basic PHP primitives. I've been bitten a couple of times by this, because you might expect that you could use an aliased type as a typehint - you can't. You can define it as a return type, though.
Collections, like Maps and Vectors (oh, it has maps and vectors), can have immutable types[6].
[3]https://docs.hhvm.com/hack/generics/introduction
[4]https://docs.hhvm.com/hack/types/type-system
[5]https://docs.hhvm.com/hack/type-aliases/introduction
[6]https://docs.hhvm.com/hack/collections/introduction
Hack also supports "async" functions[7], which really aren't asynchronous. I found it a bit difficult to get this to work with curl and SQL the way I want to, but anything that helps remove the bottlenecks of database and network requests is welcome.
[7]https://docs.hhvm.com/hack/async/introduction
To me, Hack just feels like a better more sane PHP. All of the strictness is optional, but it still feels very good to have it there, and it has features users of more modern languages would certainly find welcome.
My pitfalls, so far, are mostly the result of my own ignorance of Vagrant and what the best practices for a workflow should be. I'm still debugging stuff in nano because I don't know any better.
Also, it seems OpenShift has a HHVM module, but you can't run Composer through HHVM on it, and as a result can't run a Hack project with XHP, because of Composer dependencies that require being run under HHVM. I asked StackOverflow what to do three months ago and just got utter silence and a single downvote[8]. I'm assuming that means I either have to learn how to write my own OpenShift cartridge or pay for an account.
[8]https://stackoverflow.com/questions/38111369/using-hhvm-and-...
Which brings me to my biggest sort of pet peeve about Hack - there doesn't seem to be the sort of community around it that PHP has, and a dearth of information on certain topics.
It looks like generics aren't yet in the core language (https://wiki.php.net/rfc/generics), but I believe return type hints work. I think we're also still missing property/field type hints (https://wiki.php.net/rfc/property_type_hints).
This has its pros and cons. This means these declarations are always enforced, even when calling between typed and untyped code. However, there's no compiler to catch you out, at least not just from using the interpreter. Your IDE, or an external type checker (e.g. Phan) can check them for you, though.
PHP 7 also gives you a choice between weak and strict type coercion modes, whereas Hack lets you choose between enforced type declarations and unenforced type declarations.
As for the specific things you can type in PHP 7.0, there's parameter and return type declarations for `int`, `float`, `string`, `bool`, `array`, any class or method, and `callable` (a function name, method reference or closure). PHP 7.1 brings nullable types (prefix any type name with `?`), `iterable` (an array or an object implementing `Traversable`) and the `void` return type (enforces that a function doesn't use `return` with a value).
Notable omissions are generics (even for arrays), and property types. There was a proposal for the latter, but it was rejected, for better or worse. As bkanber mentions, however, IDEs can still check property types if they're annotated using docblocks. Hack also has a few extra special types that PHP lacks.
I wish more people gave PHP a chance and didn't just keep bagging on it. There are problems with the standard libs, but nothing that isn't bearable. Grab an IDE and it's not an issue.
Python now has type hints that allow a similar migration for existing code.
Wait, wait, wait, wait. Is he saying that to do async work he'll send a curl request to somewhere (spawning a thread for that request), not wait on the output and carry on? Last I used curl in php it was a synchronous action. Hell of a threading model there.
when i hear people say stuff like this, I assume they are a rookie dev. Have passed on many interview candidates for it.
That's not mentioned in the blog why they didn't use PHP for this.
What goes around comes around. I'm editing my LinkedIn and dusting off the old O'Reillys...
Never again.
Life's too short to waste on that junk.
Running a 2 year old framework on the Internet because the new versions include a non functional opcode cache kinda sucks.
Back when I was a green web programmer, I loved this feature. After working with Python for a good many years, I now abhor it.
> I claim that PHP’s simpler “think; edit; reload the page” cycle makes developers more productive.
Would you not use file watchers to reload the server? (especially in Node?)
I would bet a donut that Slack is off PHP within 2 years.
I know that nowadays there are a lot of fancier languages to write your next project, but I challenge anyone to find anyone that has a similar ecosystem that can do all the following things with just a matter of editing config files basically.
- Create a fully working app with authentication, database migrations, security checks, middlewares, route management, and much more with just one command line ("laravel new project_name") (Laravel)
- Logging in a user with an external service with one line of code. (Laravel Socialite)
- Sending real time notification with any type of channel. (email, socketio, sms, ios/android, ...) (Laravel Echo)
- Create a complete Oauth2 server with all the backend and frontend parts with just one configuration file. (Laravel Passport)
- Make text search with Elasticsearch using external services as easy as making a normal query to the local DB. (Laravel Scout)
- Super easy tu use payment system integration that handles both one time payments and subscriptions with Stipe and Braintree. (Laravel Cashier)
- Optimized and lightweight version of the full framework to get blazing fast APIs. (Laravel Lumen)
- Local web server that automatically creates .dev domains for each project and that works with most PHP projects (not just Laravel) (Laravel Valet)
- Vagrant box with everything you need for a local development web server. (Laravel Homestead)
- Easy frontend assets management (compiling, versioning, ...) built on top of Gulp and Webpack. (Laravel Elixir)
- Provision a web server with all the things you need (security, git push-to-deploy, ssl certificates, queue workers, ...) properly set up with one simple click. (Laravel Forge^)
- Zero downtime deployment with history backup and much more. (Laravel Envoyer^)
- Fully working SaaS app that handles all the boring stuff (subscriptions, invoicing, team management, emails, ...) and let you concentrate on the actually product you want to built. (Laravel Spark^)
- Tons of video tutorials/screencasts/lessons on how to use every aspect of Laravel and much more (PHP, Vuejs, Text editors, ...) (Laracasts)
As you can see from the list, almost everything is related to the incredibly good framework Laravel, that I highly recommend to anyone that is working or will work with PHP.
I especially recommend to all those people that are about to create their next SaaS project to take a look at Laravel Spark. It really puts all the pieces of the puzzle together and it makes your MVP really around the corner instead of months away.
Coming from old-school PHP where I hacked everything together, after learning and switching to Laravel my life as a developer completely changed and now I can't imagine that I'm still using the same language actually. They feel like two completely different things and in my opinion all those people that are talking bad about PHP, they are stuck with old memories of how PHP used to be. Yes, PHP as a language still has a lot of things that needs improving, but PHP as ecosystem of libraries and frameworks is definitely still the king of the web!
The King is dead, long live the King! :)
[^]: These are commercial products but their price is definitely accessible (99$ for Spark and 10$/month for Forge and Envoyer)
> What I think most people are missing about PHP is the incredible ecosystem that emerged in the recent years (especially with Laravel)
I would replace that last bit with: "especially with Symfony and Laravel". And composer, and all the changes made in 7.x, and lots of libraries that people build on top of it and made all of this it possible.
This is a good talk (Symfony's "creator") about the PHP ecosystem:
dotScale 2014 - Fabien Potencier - My Take on PHP https://www.youtube.com/watch?v=gpNbmEnRLBU
That thing was parroted a thousand times already and it really boils down to a personal rant about tons of legacy features rather than a properly worded criticism of the language itself.
The author is also really confused about type coercion in PHP.
It's been almost 5 years. Let it go.
Use this:
www.phpsadness.com
I have to disagree with this article. PHP is a heavily flawed language. It's very easy to get started with PHP, but there are too many pitfalls that are too easy to fall into.
Most of the "Virtues of PHP" are available in other web languages if you use the right framework. And if you use those languages you'll benefit from the consistency and predictability that come from having a clear design philosophy from the start.
I don't think PHP is a bad language. It's possible to write good software in PHP, and it's possible to work around the flaws if you really know what you're doing. If your software is already written in PHP, it's probably not worth it to throw it out and rebuild it in something else. But I don't think it's worth the trouble if you have a choice, and I think writing new software in PHP should be avoided.
I'll admit I'm not familiar with HHVM and Hack. Maybe they alleviate PHP's problems.
P.S. Most of the points under "The Case Against PHP" are also issues with Javascript. But the difference is that if you're developing a web application, you have to use Javascript. You don't have to use PHP.
I would be hesitant to dismiss the significance of those - although I'm admittedly biased, having worked with Keith previously as well as on an erstwhile "competitor" to HHVM (talariatech.com).