Live data from Hacker News

Taking PHP Seriously [pdf]

raw.github.com

91–100 of 155 posts

Re: Taking PHP Seriously [pdf]

#91

Most of the criticism of php seems to contrast it with a language plus a framework. If you really want to compare, compare php with ruby or python, not Django or RoR. As for php encouraging shitty programming, a good bit of that is that so many more people program in php because its easier to get started with. This does not mean that just because php attracts shitty programmers that it doesn't have more or many aweso…

Methinks the argument that PHP encourages shitty programming has been effectively countered by the amount of crap legacy Ruby code that has appeared several years since Rails became "hip". It should be quite obvious to anyone by now that when it comes to shitty programming, language is negligible factor once a language has hit the mainstream. But I'm pretty sure 5 to 10 years from now someone manages to argue that Ru…

I already start arguing along these lines now - starting with the refusal to define even semi-stable interfaces across versions of a library.

Instead of relying on actual reusable building blocks, you're expected to build specific versions of ruby interpreter and libraries for every project.

Imagine having to cope with just ever so slightly different (but certainly incompatible) philips screws whenever you want to affix one physical thing to another.

Re: Taking PHP Seriously [pdf]

#92

Earlier quoted context omitted.

could not get php to work for them short of rewriting the core (HPHP ) I've heard this argument before, but it's important to realize that Facebook was able to use standard PHP up until the point when they had roughly 500 million users. Unless your site has a half billion users you can't compare your use case to Facebook's.

They're making three sorts of changes: 1) removing/restricting the footguns in the language 2) adding interesting features taken from other languages (typing, traits, etc). 3) creating a new VM with better performance. As far as I can tell, only 3 is obviously something that only affects whether you can use the language once you have a certain number of users. The first two are really about changing the language.

Speaking as someone who works on a 2 million user enterprise app with standard PHP, i would have to counter that: 1) the footguns are easy to sidestep once you know them and are gradually getting removed, 2) standard php has traits and strict typing, but the typing is not for primitive types (which is what Hack adds) and 3) in nearly a decade i have had a single feature where i could have really used a faster php, whereas in practice my performance issues all come from the Oracle bottleneck because php is so easy to parallellize. Facebook could run on standard php, it would just require more hardware, and since releasing hhvm php has gotten a lot faster without breaking backwards compatibility.

Re: Taking PHP Seriously [pdf]

#93
I'm preferentially a Python programmer who is currently working on a large well-known high-Alexa-ranked website that uses the LAMP stack. The site has been around for a while and is a behemoth, so I understand why it has stayed with these technologies despite the fact that there are many people on the project at this point who'd prefer otherwise. There are both ugly workarounds and rambling boilerplate in several places due to limitations in both PHP and MySQL, and there are also other ugly portions of the codebase due to inexperienced developers or bad legacy decisions that haven't been fully refactored (not the fault of PHP or MySQL). However, there is also a good deal of work that is well thought out and architected so I no longer have as many qualms about PHP as I used to (that I now realize was due to being thrown into codebases that were just a mishmash of crap... there do seem to be more of those in PHP than in other languages, but that's just my personal exposure).

All the same, if you're not inheriting a legacy codebase, I don't think there is any reason to use a LAMP stack on a greenfield project that you will be creating tomorrow. There are just too many better alternatives out there.

Re: Taking PHP Seriously [pdf]

#94

Most of the criticism of php seems to contrast it with a language plus a framework. If you really want to compare, compare php with ruby or python, not Django or RoR. As for php encouraging shitty programming, a good bit of that is that so many more people program in php because its easier to get started with. This does not mean that just because php attracts shitty programmers that it doesn't have more or many aweso…

Methinks the argument that PHP encourages shitty programming has been effectively countered by the amount of crap legacy Ruby code that has appeared several years since Rails became "hip". It should be quite obvious to anyone by now that when it comes to shitty programming, language is negligible factor once a language has hit the mainstream. But I'm pretty sure 5 to 10 years from now someone manages to argue that Ru…

If I'm a least-common-denominator web developer and I copy and paste some PHP code into a project from a google search, and I copy and paste some Ruby code of similar origin, what are the odds that each has a inobvious flaw?

Or much worse what are the odds that if I'm an average developer and am picking a random feature from each language's standard library, making care to read the docs before using it in my application that I've still introduced a bug? (Consider that maybe I'm dealing with things that were considered strange and new when most of PHP is still from - like character encodings - particularly character encodings that differ from the system I'm running in).

Most languages can be CGI-style executed by an httpd with shared-nothing, but can also start up and be a long-lived stateful daemon. I don't have to decide between putting a square peg in a round hole or throwing my code away to learn something entirely new if I realize I need the latter part way through a project.

PHP comes with a excessively large (but strangely CGI/HTTP/HTML/SQL-obsessed) standard library littered with footguns, and for most of its life has not had a common pattern for reusable modules, and has not had a good bundler for shipping reusable modules or making working with C extensions easy - and as such few people bother reimplementing functionality from core outside of what's been provided there (which is all set in hard clay), and when they are forced to tend to do so in (plain-ole-interpreted) PHP and don't generally package it up for reuse outside their own projects - a practice much more common outside PHP-land.

Case in point (goddamn strlen, even): https://api.drupal.org/api/drupal/includes%21unicode.inc/fun...

Some of that is changing in recent history (as in well after other languages figured these problems out) with PSR (design for reuse) and Composer (bundler) but it's slow moving and the latter still won't compile C extensions yet: https://github.com/composer/composer/pull/498

Plenty of this could be solved in PHP, some of it already is if you have the luxury to work with a tiny subset of PHP projects, but the practice in PHP seems to still mostly be to have it piss in your face and believe that it's raining. People are in a rut of tradition or simply don't expect their tools or libraries to be good - and I've spent the last 6 years working with PHP (several products, several teams) and wondering where I can get some of the Koolaid that my colleagues are drinking.

Re: Taking PHP Seriously [pdf]

#95

Before this turns into a recanting of the points in the "PHP is a double-clawed hammer" post again, I would like to remind people that PHP still has a place in the business world that nno other language has stepped up to fill. http://blog.samuellevy.com/post/41-php-is-the-right-tool-for... Please stop complaining about how horrible PHP is if you don't use it or have. intentions to replace it.

I couldn't agree more. Having worked with clients that publish thousands of articles of content per month the best solution for the job at the end of the day is still WordPress. Have a client that needs an online store? Magento (both of which are built in PHP). Development shops don't have time to custom build CMS's and eCommerce solution because their clients don't give a shit what language or framework their site i…

In my experience Spree is better than Magento for most smbs. You are right,however, there is no replacement for WordPress and its ecosystem. Ghost looks interesting, though.

Re: Taking PHP Seriously [pdf]

#96
post #88

Earlier quoted context omitted.

Why can't you use getMockBuilder() for static methods? (I don't know PHPUnit so maybe it's a stupid question.)

These tools only work when: 1) You've implemented dependency injection, or 2) You're using a container For example, in PHP you can't mock something like "$foo = new Bar();". The code is right there, it's saying exactly what it wants, you can't return a fake class (unless you do some ugly magic). However, you can pass in an object that is_a Bar, either injecting it via DI or storing it and then retrieving it from a co…

Procedural testing isn't hard.

All that dependency crap is only a result of your AbstractTestingFrameworkMethodFactoryClassMockMethodGenerator() and similarly useless abstractions, anyway.

A simple module system can be implemented in a single function and referenced from test code as easily as:

test_requires('module1','module2');

Purely procedural tests are as easy as:

assert_equals(function_one('example_input'),'expected_output'); assert_not_equals(function_two(true),false);

Full featured test framework:

function assert_equals($a,$b) { return $a==$b; } function assert_not_equals($a,$b) { return $a!=$b; }

(Edit: I don't believe I missed the point - 'dependency injection', a recent term in PHP, essentially means tightly coupling to an entire DI system instead of directly to a single dep as demonstrated above. Either way, loose coupling is a concept to strive for as far as reasonably possible - not an absolute requirement. If your code requires something else, then it requires something else. The solution is not to create a new AbstractPretenderOfTotalWorldVisibilityEvenThoughControlFlowIsNowAllOverTheShop() After all, if you carry that tight coupling argument further you could claim that by virtue of writing PHP at all you are tight coupling to a certain, if broad, class of processor architectures. There has to be a limit somewhere! Mostly, that's determined by legibility/maintaintability and programmer time, not by abstract measures of correctness.)

Re: Taking PHP Seriously [pdf]

#97

Earlier quoted context omitted.

They're making three sorts of changes: 1) removing/restricting the footguns in the language 2) adding interesting features taken from other languages (typing, traits, etc). 3) creating a new VM with better performance. As far as I can tell, only 3 is obviously something that only affects whether you can use the language once you have a certain number of users. The first two are really about changing the language.

Maybe I should have expressed myself more clearly: The comment I replied to seemed to indicate that PHP must be bad since Facebook had a need to change it. My point was that, given the fact that Facebook has way more users than other sites and mostly serves non-cacheable pages, their needs are different than the needs of 99.9999% of other sites in the world, so the fact that they were forced to change PHP doesn't say…

The # of users really says nothing about how expressive the language you're programming in is.

And if we're talking about consumer products like facebook, it doesn't even say anything about how fast your programming language is since performance is dominated by database access time.

At best, we can try and claim that Facebook found PHP to be insufficiently expressive/safe/suited for them once they had X number engineers making Y number of changes per day.

Maybe they really could "move fast and break stuff" with 200+ engineers trying to commit to a vanilla PHP codebase.

Re: Taking PHP Seriously [pdf]

#98
post #59

Before this turns into a recanting of the points in the "PHP is a double-clawed hammer" post again, I would like to remind people that PHP still has a place in the business world that nno other language has stepped up to fill. http://blog.samuellevy.com/post/41-php-is-the-right-tool-for... Please stop complaining about how horrible PHP is if you don't use it or have. intentions to replace it.

I actually feel the same way about "classic" ASP. Yeah, it wasn't pretty. But for simple CRUD pages of the day, it was damn simple and you didn't need ninjas or rockstars to get stuff done.

I remember asp classic. It was the defacto standard for programming on the web, until something better replaced it. That something was PHP.

PHP means access to easy to install, ready to go software, which meets 95% of the needs of small businesses. I would love to see that in python, or anything else, but it simply isn't there. The most widely used python CMS? Plone. It's massive, hard to maintain, and far from easy to install or host.

I've been on and off working on systems like WordPress for pyramid/python for a while, but it's a massive project. One day I might finish it...

Re: Taking PHP Seriously [pdf]

#99
post #61

Earlier quoted context omitted.

Deployment, for one. sudo apt-get install Apache and PHP, then edit the Apache config to say, "use this directory." I love Django and Flask to pieces, but deploying a Python app is like building a hovercraft compared to PHP.

I have no problems deploying a django app with gunicorn. It's a simple command line statement, and deployment is always an intricate thing, unless you don't have to worry about ssl certs and secrets and keys, and managing access, admin pages, etc etc.

Which you usually don't for fun personal projects.

Re: Taking PHP Seriously [pdf]

#100

I like the look of this "hack". It adds things to PHP that I missed from C# .. now if they will add Accessors syntax, that would be nice, especially for those that use Doctrine2. PHP is as professional of a language as the user. I found fun working with PHP, C#, (node)js, python and think each has its own way, quirks and benefits.

You can easily add something like accessors using traits. I cooked this up in 5 minutes: https://gist.github.com/jsebrech/6740010

You can do a lot with meta-programming in PHP. For example, you can write your own array type if you are so inclined and use it anywhere you would use an array. Here's an experimental library that showcases the meta-programming abilities: https://github.com/jsebrech/php-o

Post reply on HN