4 ms·
There is a reason why facebook used PHP, wordpress is in PHP, and a lot of other tools are also. PHP is popular, it's easy to find developers who will write it
by EGreg 16y ago
There is a reason why facebook used PHP, wordpress is in PHP, and a lot of other tools are also. PHP is popular, it's easy to find developers who will write it in it, and it's also easy to find PHP hosting for noobs. When there is a popular platform, you will get lots of apps written on it.
That said, the high art of PHP was always to make really performant apps while having your code as organized as possible. These days, this is being done very well with files, autoloading, and opcode caching. If you do things this way, Rasmus would be happy, and things would be fast.
I am a PHP developer. A lot of what I saw in the past few years was frameworks like Cake and symfony that basically copied Rails or brought some heavy techniques with a lot of overhead. This is not the PHP way. If you want to see a framework that does things in a more PHP way, I would humbly submit my own:
http://phponpie.com http://phponpie.com
It's open source. It's called PHP On Pie for a reason: because it's easy and it uses real PHP techniques, not tries to emulate Ruby or Python. PHP has its own beauty, such as arrays which can support numeric and string indexes at the same time.
All this said, these days PHP is outdated for large sites. Not because there is a lot of crap written in it -- which I agree with. But because it still works only synchronously, and the culture is too server-heavy. Large sites should be written like this:
Clients (browser, etc.) do most of the interface logic.
Components should render themselves using javascript, and only use the server for data
Server does web services (REST, socket push, etc.)
Server should not have to do things synchronously.
Node.js rocks in this respect. Unlike PHP, I can literally issue 10 independent queries to 10 different databases and combine the results as they come in. In PHP, I would have to issue this stuff sequentially. That's slow.
The second thing in PHP is fixable. People should move most of the logic (that doesn't need authentication) to the client side, and then write all their web services in a very simple way. Stop generating all your HTML on the server. Check out
http://weblog.rubyonrails.org/2011/4/18/why-http-streaming http://weblog.rubyonrails.org/2011/4/18/why-http-streaming
and
http://www.facebook.com/notes/facebook-engineering/bigpipe-pipelining-web-pages-for-high-performance/389414033919 http://www.facebook.com/notes/facebook-engineering/bigpipe-p...
- aphyr 16y agoPHP has its own beauty, such as arrays which can support numeric and string indexes at the same time. Rarely do I actually spit on my keyboard. Not only do most other languages do associative arrays properly, so, you know, numeric and string indices don't clobber each other, but they also don't explode when indexed with, say, anything but decimal literals. You seriously think this is beautiful behavior? http://aphyr.com/journals/show/fun-with-php-arrays http://aphyr.com/journals/show/fun-with-php-arrays
- nickik 16y agoSomething hit my monitor too :) I have to tiwtter this.
- Androsynth 16y agoIf you write sloppy code, expect unexpected behavior. Your examples are as bad as any other junk out there. The advantage of php arrays (imho) is that you can treat them as associative arrays or not dependening on the situation. The lookup behavior is the same for both though, which is convenient. i don't know python or ruby enough to compare, but it is nicer than javascript where associative arrays (ie objects) and real arrays are entirely different types.
- edtechre 16y agoI write way more PHP than Python. But dicts are MUCH better in Python. In fact, dict keys can be any data type you choose, like a true hash table in other languages like Java (e.g. HashMap).
- Stormbringer 16y agoDon't blame the tool user for inconsistencies in the tool. A claw hammer that occasionally bites your hand off is a bad claw hammer. (Bad! No biscuit!)
- Androsynth 16y agoThe general consensus of this thread is that there are a lot of bad php developers out there that write bad code and this does serious discredit to the language. The example this poster linked to was bad code. Its not proof the language is bad, its proof the poster is no better than the truly bad programmers who use the language he is trying to make fun of.
- jessedhillon 16y agoIn PHP: $bool = (08 === 0); var_dump($bool); This prints bool(true) In other words, at the deepest level of identity this language can check, 08 is reported to be equal to 0. With a language like that, I think it's safe to blame the tool.
- mccutchen 16y ago> PHP has its own beauty, such as arrays which can support numeric and string indexes at the same time. What's the difference between PHP's arrays and hashtables/dictionaries/etc in languages like Python, Ruby, and JavaScript? As a Python programmer (who started with PHP years ago), PHP's arrays now seem sort of muddled or confusing. I prefer Python's dedicated list/dict types (though nothing is stopping you from mixing numeric and string keys in a dict).
- EGreg 16y agoDon't get me wrong, I like Python's data types very much. And it's certainly nice to have the ability to have more low-level control over how your array is stored. I mean beauty in the sense of appreciating something. Just because your wife isn't a supermodel, doesn't mean you cannot find her beautiful and have a good marriage. Once you accept PHP for what it is, you find that there's a certain file-oriented style of coding that is perfectly suited to it, that embraces the unique type of PHP arrays, and that autoloads files when needed. In PHP, you have an array that is basically associative, BUT which you can iterate in the same order that keys are added. This data structure is very unique and often lets you write less code, since you don't have to store the order separately. It also happens to map to JSON very well. Javascript has something like this too, except there is no guarantee that all browsers will implement properties in the same order, and many people on the internet complain about this sort of thing: http://code.google.com/p/chromium/issues/detail?id=883 http://code.google.com/p/chromium/issues/detail?id=883 http://code.google.com/p/chromium/issues/detail?id=20144 http://code.google.com/p/chromium/issues/detail?id=20144 I have to say, I feel for those guys.